Linked list:-

A linked list is a set of dynamically allocated nodes, arranged in such a way that each node contains one value and one pointer. The pointer always points to the next member of the list. If the pointer is NULL, then it is the last node in the list. A linked list is held using a local pointer variable which points to the first item of the list. If that pointer is also NULL, then the list is considered to be empty.

Types of linked list:-


Singly linked list
Doubly linked list
Circular linked list
Doubly circular linked list


Program showing the working of linked list:-


#include< stdio.h>
#include< conio.h>
#include< alloc.h>
struct node
{
int data;
struct node *next;
};
typedef struct node list;
list *head;
void create();
void display();
void search();
void count();
void main()
{
int num;
head=(list *)malloc(sizeof(list));
create(head);
display(head);
count(head);
printf("what to search");
scanf("%d",&num);
search(head,num);
getch();
}
void create(list *head)
{
printf("enter a value (-9) to stop");
scanf("%d",&head->data);
if(head->data==-9)
{
head->next=0;
}
else
{
head->next=(list *)malloc(sizeof(list));
create(head->next);
}
}
void display(list *head)
{
if(head->next!=0)
{
printf("%d",head->data);
display(head->next);
}
}
void count(list *head)
{
static int c=0;
if(head->next!=0)
{
c=c+1; count(head->next);
}
printf("%d nodes are available",c);
}
void search(list *head,int n)
{
if(head->data==n)
{
printf("found");
}
else
{
search("head->next");
}
}