Doubly Linked List (DLL) Traversing- Backward and Forward


Traversing or Visiting:- Accessing or visiting of each node present in Doubly Linked List is known as Traversing. It is of two types -
ट्रेवर्सिंग या विसिटिंग:- डबली लिंक्ड लिस्ट के सभी नोड्स को एक्सेस या विजिट करना, ट्रेवर्सिंग कहलाता है। यह दो प्रकार से की जा सकती है-
1.) Forward traversing (आगे की ओर ट्रेवरसींग)
2.) Backward traversing(पीछे की ओर ट्रेवरसींग)

Let Assume that DLL was previously created by createdll() and first is pointing to the fisrt node and last is pointing to the last node of DLL.
माना कि createdll() द्वारा DLL तैयार की गयी है, जिसके प्रथम नोड का एड्रेस फर्स्ट एवं अंतिम नोड का एड्रेस लास्ट नामक पॉइंटर वेरिएबल में रखा गया है  

//Forward Traversing in DLL

void traversefdll(){
NODE *temp=first;
int i=0;
clrscr();
if(temp==NULL){
printf("Doubly Linked List is Not Exist\n");
getch();
return;
}
printf("Doubly Linked List is:-\n");
while(temp!=NULL){i++;
printf("Node No:-%d\nback part=%u\ninfo part= %d\nnext Part=%u\n",i,temp->back,temp->info,temp->next);
temp=temp->next;
}
printf("Linked List Traversed \n %d Node's are Visited.\nfirst=%u and last=%u",i,first,last);
getch();
return;
}
 
//Backward Traversing in DLL

void traversbdll(){
NODE *temp=last;
int i=0;
clrscr();
if(temp==NULL){
printf(" Doubly Linked List is Not Exist\n");
getch();
return;
}
printf("Doubly Linked List in Backward direction is:-\n");
while(temp!=NULL){i++;
printf("Node No:-%d\nback part=%u\ninfo part= %d\nnext Part=%u\n",i,temp->back,temp->info,temp->next);
temp=temp->back;
}
printf(" Doubly Linked List Traversed \n %d Node's are Visited.\nfirst=%u and last=%u",i,first,last);
getch();
return;
}

Comments

Popular posts from this blog

Priority Queue

Data Structure and Algorithms (DSA) USING C/C++ Topics Covered