Linear Data Structure 497
iteml.p=item2.n;
itemO.n«7;
itemO .p*iteml.n;
clrscrO ;
printf ( ”n Linked li s t elements are: ■);
printf (■ %d " , itemO.n);
printf (" %d " , itemO.p);
printf (" %d " , iteml.p);
printf ( ” %d ”,item2.p);
}
QUTTUT;
Linked list elements are: 7 5 3 0
Explanation In the above program the structure list is declared with two elements int n and *p.
The pointer *p recursively points to the same structure. The struct itemO, iteml and item2 are three
variables of type list Consider the initialization given below.
item2.n=3;
item2.p=NULL;
The item2 is the third (last) node of the list. The pointer p is initialized with NULL. This is because
next to this no node is present and thus there is no need to point to any address.
iteml.n=5;
iteml .p=item2.n;
In this node, n is assigned a value of 5. The pointer points to the data field of the next node, that is,
item2.n (7).
item0.n=7;
item0.p=iteml.n;
14.19 LIN K ED L IS T W ITH AN D W IT H O U T HE A D E R
Linked List w ith H eader
The following steps are used to create a linked list with header.
1) Three pointers—header, first and rear—are declared. The header pointer is initially initialized
with NULL. For example, header=NULL, where header is pointer to structure. If it remains NULL
it implies that the list has no element. Such a list is known as a NULL list or an empty list.
NULL
2) In the second step, memory is allocated for the first node of the linked list. For example, let the
address of the first node be 1888. An integer, say 8, is stored in the variable num and the value of
header is assigned to pointer next.
Header