Académique Documents
Professionnel Documents
Culture Documents
Doubly-linked list: doubly-linked list is a linked data structure that consists of a set of data
records, each having two special link fields that contain references to the previous and to the next
record in the sequence. It can be viewed as two singly-linked lists formed from the same data
items, in two opposite orders.
A doubly-linked list whose nodes contain three fields: an integer value, the link to the next node, and the link to the
previous node.
The two links allow walking along the list in either direction with equal ease. Compared to a singly-
linked list, modifying a doubly-linked list usually requires changing more pointers, but is sometimes
simpler because there is no need to keep track of the address of the previous node.
Circularly-linked list: In a circularly linked list, all nodes are linked in a continuous circle,
without using null. For lists with a front and a back (such as a queue), one stores a
reference to the last node in the list. The next node after the last node is the first node.
Elements can be added to the back of the list and removed from the front in constant
time.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<alloc.h>
#define null 0
struct node
{
int info;
struct node *link;
}*start;
void main()
{
int ch,n,m,position,i;
last=null;
while(1)
{
printf("1.create
2.addat
3.addbt
4.del
5.disp
6.exit
");
printf("er ur ch");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("er no of itc");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("er the element");
scanf("%d",&m);
create(m);
}break;
case 2:
printf("er the element");
scanf("%d",&m);
addat(m);
break;
case 3:
printf("er the element");
scanf("%d",&m);
addat(int data)
{
if(q->info==data)
{
tmp=q;
last->link=q->link;
free(tmp);
return;
}
while(q->link!=last)
{
if(q->link->info==data)
{
tmp=q->link;
q->link=tmp->link;
free(tmp);
printf("element %d is deleted",data);
}
if(q->link->info=data)
{
tmp=q->link;
q->link=last->link;
free(tmp);
last=q;
return;}
printf("element%d is not found",data);
}
disp()
{
struct node *q;
if(last==null)
{
printf("list isdempty");
return;
}q=last->link;
while(q!=last)
{
printf("%d",q->info);
q=q->link;
}
printf("%d",last->info);
}