Upload
bella-angel
View
3
Download
0
Embed Size (px)
DESCRIPTION
using c/c++ complete code to implement data structure of dubly link list
Citation preview
#include"Node.cpp"#include#include
class list{public:list(){headnode=new Node();headnode->setnext(NULL);headnode->setprevious(NULL);currentNode=NULL;lastcurrentnode=NULL;size=0;};Node* getheadnode(){return headnode;};Node* getcurrentnode(){return currentNode;};void setcurrentnode(Node* cn){this->currentNode=cn;};int Get(){if(currentNode!=NULL)return currentNode->get();};void add(int addobj){Node* newnode=new Node();newnode->set(addobj);if(currentNode!=NULL){newnode->setnext(currentNode->getnext());newnode->setprevious(currentNode);//(currentNode->getnext())->setprevious(newnode);currentNode->setnext(newnode);currentNode=newnode;}else{newnode->setnext(NULL);newnode->setprevious(headnode);headnode->setnext(newnode);lastcurrentnode=currentNode;currentNode=newnode;}size++;};void print(){Node* p;p=headnode->getnext();if(p==NULL){coutnextNode;}else{(currentNode->getprevious())->setnext(currentNode->getnext());currentNode->getnext()->setprevious(currentNode->getprevious());Node* temp;temp=currentNode;currentNode=currentNode->getnext();coutsetnext(nn);copylist.currentNode=nn;l.currentNode=l.currentNode->getnext();}while(l.currentNode!=NULL){
Node* nn=new Node();nn->set(l.currentNode->get());nn->setnext(NULL);nn->setprevious(l.currentNode->getprevious());copylist.currentNode->setnext(nn);copylist.currentNode=nn;l.currentNode=l.currentNode->getnext();}copylist.print();
};public:Node* headnode;Node* currentNode;Node* lastcurrentnode;int size;};enum choice {add=1,insert,search,remove1,update,print,copy1,size,END}; int enterChoice() { cout