512 Programming and Data Structures
i f (k»4t:1) p r-firs t;
if (ct-k) pr-header;
if (c -«(k + l)) subheader;
}
nw= (struct num*) m alloc(sizeof(struct num));
printf ("n Enter a element : ■);
scanf ("%d", &nw->num);
pr->next«nw;
nw->next-su;
header-first;
}
void show()
{
printf ( ”n Linked li s t elements are : ”);
while (headerI-NULL)
{
printf (" %d ", header- >num);
count++;
header-header->next;
}
header-first;
}
Operation creation:
Enter number 1 2 3 4 5 0
Linked list elements are: 1 2 3 4 5
Enter position (upto 5 )number (After):3
Enter a element: 8
Linked list elements are: 1 2 8 3 4 5
Explanation In the above program the operation, creation and display of linked nodes is similar
to that explained in the last programs. Here, we are going to discuss insertion at a particular position
carried out by a function ato p ( - - p ) . The position number is specified by the user, after reducing
the value by one it is passed to function atop (). The variable k, formal argument of p, gets this
value. Another variable c is declared in the body of ato p (). The variable c is incremented and
successive nodes of the linked list are accessed by the statement header=header - >next.