1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
Node Class
# include <iostream.h>
# include <conio.h>
class Node {
private:
Node* link;
Node* prev;
int info;
public:
Node(){link=NULL; prev=NULL; info=-1;}
Node(Node* front, Node* back, int x){link=front; prev=back; info=x;}
void SetLink(Node* l){link=l;}
void SetPrev(Node* p){prev=p;}
void SetInfo(int x){info=x;}
int GetInfo(){return info;}
Node* GetLink(){return link;}
Node* GetPrev(){return prev;}
};
List Class
class List {
private:
Node* start;
public:
void create(){start=NULL;}
Append Method
void append(int x){
Node *node=new Node();
node->SetInfo(x);
node->SetLink(NULL);
node->SetPrev(NULL);
if(start==NULL) start=node;
else {
Node* temp=start;
while(temp->GetLink()!=NULL) temp=temp->GetLink();
temp->SetLink(start);
temp->SetPrev(node);
start=node; }
}
Display Method
void display() {
Node* temp=start;
while (temp!=NULL) { cout<<"DATA"<<"--->"<<temp->GetInfo()<<"\n";
temp=temp->GetLink();}
}
}; |