Linked_List_intro
Linked_List_intro
LINKED LIST:
(CREATE, TRAVERSE AND SEARCH OPERATION)
Introduction
• A linked list is a data structure which can change
during execution.
– Successive elements are connected by pointers.
– Last element points to NULL.
– It can grow or shrink in size during execution of a program.
– It can be made just as long as required.
– It does not waste memory space.
head
A B C
A B C
A B C
– Circular linked list
• The pointer from the last element in the list points back
to the first element.
head
A B C
Creating a List
How to begin?
• To start with, we have to create a node (the
first node), and make head point to it.
head = (node *)
malloc(sizeof(node));
roll
name
head
age
Contd.
• If there are n number of nodes in the initial
linked list:
– Allocate n records, one by one.
– Read in the fields of the records.
– Modify the links of the records so that the chain is
formed.
head
A B C
node *create_list()
{
int k, n;
node *p, *head;
printf ("\n How many elements to enter?");
scanf ("%d", &n);