Rosetta Code talk:Add a Task: Difference between revisions

Undo revision 356418 by Yasser Mohammed (talk) Not the place
(Undo revision 356418 by Yasser Mohammed (talk) Not the place)
 
(10 intermediate revisions by 3 users not shown)
Line 5:
 
==First implementation==
I certainly like the requirement for an implementation. It almost always makes things much easier for other implementers if they can study a working example. Perhaps the requirement for graduating a task from draft status should be taken to be multiple implementations of it and a consensus that the task is clear enough (typically formed by having multiple implementations that people can agree are all correct). –[[User:Dkf|Donal Fellows]] 21:06, 21 September 2010 (UTC)
One of the key aspects of Software Engineering is to avoid reinventing the wheel. Reusability is always preferred.
 
: Hi Donal, I would think that you don't actually have a task, draft or not, without that first implementation. They go together for me.<br> I don't often use the draft task status, and its usually when I find something that interests me, but I am unsure of wider interest, or might shift the focus of a task, as in [[Talk:Simple Quaternion type and operations]], and [[Talk:Short-circuit evaluation]], and [[Talk:Extreme floating point values]], and [[Horner's rule for polynomial evaluation]] - started as a draft I think because I couldn't get the formatting of the equations in the description right. --[[User:Paddy3118|Paddy3118]] 05:47, 22 September 2010 (UTC)
 
==Other Algorithms==
Line 20 ⟶ 22:
 
:::Just for another way to think about it, maybe we can say that Cateories are DB tables where the keys are the page names. Then Properties would be tables where the keys are the page name and an additional value. --[[User:Mwn3d|Mwn3d]] 22:27, 9 November 2010 (UTC)
 
== C++ linkedlist implementation by me ==
 
 
== //- University of Delhi
//- by Manish Natraj shohbby
// - c++ list
#include <iostream>
#include <cstdlib>
using namespace std;
template <class T>
struct node
{
T data;
node * next;
node * pre;
};
template <class T>
class list
{
public:
class Iterator
{
public:
node<T>* it ;
Iterator()
{
it = NULL;
}
void operator ++()
{
if(it!=NULL)
it = it->next;
}
void operator ++(int)
{
if(it!=NULL)
it = it->next;
}
void operator --()
{
if(it!=NULL)
it = it->pre;
}
void operator --(int)
{
if(it!=NULL)
it = it->pre;
}
T& operator * ()
{
return it->data;
}
bool operator==(const Iterator * x)
{
return (it==x.it);
}
};
list()
{
node<T> * dummy = new node<T> ;
head = tail = dummy;
head->pre =NULL;
}
list(T value, int size)
{
node<T> * n ;
node<T> * dummy = new node<T> ;
head = tail = dummy;
head->pre =NULL;
for(int i=0 ; i<size ; i++)
{
n = new node<T>;
n->data = value ;
n->next = head;
head->pre = n;
head = n ;
}
}
~list()
{
node<T> * temp ;
while (head!=tail)
{
temp = head ;
head = head->next;
delete temp;
}
delete tail;
}
void print()
{
node<T> * temp = head ;
while (temp!=tail)
{
cout<<temp->data<<" ";
temp = temp->next;
}
}
int size()
{
int count = 0;
node<T> * temp = head ;
while (temp!=tail)
{
count++;
temp = temp->next;
}
return count ;
}
void insert(T value, Iterator p)
{
node<T> * temp = head ;
node<T> * temp1 ;
node<T> * n = new node<T> ;
n->data = value;
if(head == p.it)
{
n->next = head;
n->pre = NULL;
head->pre=n;
head = n;
return;
}
if(tail == p.it)
{
tail->data = value;
tail->next = n;
n->pre= tail;
tail = n;
return;
}
while (temp!=p.it)
{
temp1 = temp ;
temp = temp->next;
if(temp==tail)
{
return;
}
}
temp1->next = n ;
n->pre= temp1;
n->next = temp ;
temp->pre=n;
}
void erase(Iterator p)
{
node<T> * temp = head ;
node<T> * temp1 ;
if(p.it == tail )
{
cout<<" no location found "<<endl;
return;
}
else if (p.it == head )
{
head = head->next;
head->pre = NULL ;
delete temp;
return;
}
while (temp!=p.it)
{
temp1 = temp ;
temp = temp->next;
if(temp == tail)
{
cout<<" no location found "<<endl;
return;
}
}
temp1->next = temp->next;
temp->next->pre = temp1;
delete temp;
}
list<T>& operator= (const list<T> & l)
{
node<T> * temp ;
node<T> * temp2 = l.head ;
while (head!=tail)
{
temp = head ;
head = head->next;
delete temp;
}
temp2 = l.tail->pre;
while (temp2!=NULL)
{
insert(temp2->data, begin());
temp2=temp2->pre;
}
}
Iterator begin ()
{
Iterator i ;
i.it = head ;
return i ;
}
Iterator end()
{
Iterator i ;
i.it = tail ;
return i ;
}
private:
node<T> * head ;
node<T> * tail ;
};
 
 
int main()
{
list <int> l(3,5);
list <int> l2(2,4);
l.print();
cout<<endl << "size = " << l.size();
list<int>::Iterator it = l.begin();
++it;
l.insert(9,it);
cout << " data = "<< *it << endl ;
it=l.end();
l.insert(4,it);
cout << "data = "<< *it << endl ;
cout<<endl;
l.print();
it=l.end();
l.insert(7,it);
cout<<endl;
cout << " data = "<< *it << endl ;
l.print();
it=l.begin();
l.erase(it);
cout<<endl;
l.print();
it=l.begin();
it++;
l.erase(it);
cout<<endl;
l.print();
l2 = l;
cout<<endl;
l2.print();
return 0;
}
==
10,327

edits