#include<stdio.h>
#include<conio.h>
struct node
{
int no;
struct node *next;
struct node *back;
};
struct node *head;
struct node *p;
struct node *temp;
void main()
{
int ctr,no;
char ch;
void disp();
void ins();
void del();
clrscr();
head=(struct node*)malloc(sizeof(struct node));
p=head;
printf("\nEnter the value::");
flushall();
scanf("%d",&head->no);
printf("\nDo u want to create another node:::");
flushall();
scanf("%c",&ch);
while(ch=='y'||ch=='Y')
{
p->next=(struct node*)malloc(sizeof(struct node));
p=p->next;
printf("\nEnter the value::");
flushall();
scanf("%d",&p->no);
printf("\nDo u want to create another node:::");
flushall();
scanf("%c",&ch);
}
p->next=head;
printf("\n1)Insert\n2)Delete\n3)Display");
flushall();
scanf("%d",&no);
if(no==1)
{
ins();
}
getch();
}
void disp()
{
temp=head;
p=head;
printf("%d",head->no);
temp=temp->next;
while(temp!=head)
{
printf("\n%d",temp->no);
temp=temp->next;
}
printf("\n%d",head->no);
}
void ins()
{
int num,after;
printf("\n1)Begining\n2)Middle\n3)End");
flushall();
scanf("%d",&num);
temp=(struct node*)malloc(sizeof(struct node));
printf("\nEnter the value::");
flushall();
scanf("%d",&temp->no);
if(num==1)
{
p=head;
while(p->next!=head)
{
p=p->next;
}
temp->next=head;
p->next=temp;
head=temp;
}
if(num==2)
{
printf("\nAfter which node u want to insert::");
flushall();
scanf("%d",&after);
p=head;
while(p->no!=after)
{
p=p->next;
}
temp->next=p->next;
p->next=temp;
}
if(num==3)
{
p=head;
while(p->next!=head)
{
p=p->next;
}
temp->next=head;
p->next=temp;
}
disp();
}
void del()
{
int num,after;
printf("\n1)Begining\n2)Middle\n3)End");
flushall();
scanf("%d",&num);
}