Page 99 - DCAP407_DATA_STRUCTURE
P. 99
Data Structure
Figure 6.1 depicts the traversal of a list. The figure shows a list consisting of HEAD or the START node
pointing to the first node (Node1). The last node (Node4) points to NULL indicating the end of the list.
It also includes a pointer variable named current to point to the next node.
Figure 6.1: Linked List Traversal
The list traversal can be achieved by using a while loop for every loop iteration. The pointer variable
points to the next node and thus all the nodes in the list can be processed.
The program shows the implementation of a traversal of a linked list and displays
the elements present in a list.
#include<stdio.h>
#include<conio.h>
int LIST[20];
int LIST1[20];
int HEAD;
void MULT(int);
void main()
{
Int PTR;
Clrscr();
LIST[0] =55;
LIST[2]=15;
LIST[3]=20;
LIST[5]=65
LIST[7]=35;
LIST[8]=66;
LIST[9]=12;
LIST[11]=6;
LIST[13]=75;
LIST[14]=80;
LIST[16]=79;
LIST[18]=39;
LIST1[0]=3;
LIST1[2]=13;
LIST1[3]=2;
LIST1[5]=8;
LIST1[7]=14;
92 LOVELY PROFESSIONAL UNIVERSITY