Vous êtes sur la page 1sur 5

Md:Nurul islam

Id:102-15-1081 (cseL2 T4)

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.

Code of circular lilked list:

#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);

printf("er the position");


scanf("%d",&position);
addbt(m,position);
break;
case 4:
if(last==null)
{
printf("list is empty");
continue;
}
printf("er the element for delete");
scanf("%d",&m);
del(m);
break;
case 5:
disp();
break;
case 6:
exit(0);
break;
default:
printf("wrong choice");
}
}
}
create(int data)
{
struct node *q,*tmp;
tmp=(struct node *)malloc(sizeof(struct node));
tmp->info=data;
tmp->link=null;
if(last==null)
{
last=tmp;
tmp->link=last;
}
else
{
tmp->link=last->link;
last->link=tmp;
last=tmp;
}}

addat(int data)
{

struct node *q,*tmp;


tmp=(struct node *)malloc(sizeof(struct node));
tmp->info=data;
tmp->link=last->link;
last->link=tmp;
}
addbt(int data,int pos)
{
struct node *tmp,*q;
int i;
q=last->link;;
for(i=0;i<pos-1;i++)
{
q=q->link;
if(q==last->link)
{
printf("there r lessthan %d elements",pos);
return;
}
}
tmp=(struct node *)malloc(sizeof(struct node));
tmp->link=q->link;
tmp->info=data;
q->link=tmp;
if(q==last)
last=tmp;
}
del(int data)
{
struct node *tmp,*q;
if(last->link==last&&last->info==data)
{
tmp=last;
last=null;
free(tmp);
return;
}
q=last->link;

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);
}

Vous aimerez peut-être aussi