Showing posts with label sg web solutions. Show all posts
Showing posts with label sg web solutions. Show all posts

Saturday, June 4, 2016

WAP to implement Double Ended Restricted Queue

#include<stdio.h>
#include<conio.h>
int dq[5],r=-1,f=-1,r2=5,f2=5,max=5;
void insertr(int x)
{
if(r==max-1)
{
printf("Queue is full");
return;
}
r++;
dq[r]=x;
if(f==-1)
f=0;
r2=f;
f2=r;
}
int deletel()
{
int x;
if(f==-1)
{
printf("Queue is empty");
}
else
{
x=dq[f];
if(f==r)
{
f=r=-1;
f2=r2=max;
}
else
{
f++;
f2=r;
r2=f;
}
return x;
}
}
void insertl(int x)
{
if(r2==0)
{
printf("Queue is full");
return;
}
r2--;
dq[r2]=x;
if(f2==max)
f2=max-1;
r=f2;
f=r2;
}
int deleter()
{
int x;
if(f2==max)
{
printf("Queue is empty");
}
else
{
x=dq[f2];
if(f2==r2)
{
f=r=-1;
f2=r2=max;
}
else
{
f2--;
f=r2;
r=f2;
}
return x;
}
}
void display()
{
int i;
if(f==-1)
{
printf("\nQueue is empty");
return;
}
printf("\n Values in queue are:\n");
for(i=f;i<=r;i++)
{
printf("|%d| ",dq[i]);
}
}
void main()
{
int n,x,res,typ;
clrscr();
printf("\n1. Input restricted");
printf("\n2.Output Restricted");
printf("\nEnter restriction type:");
scanf("%d",&res);
switch(res)
{
case 1:
printf("\n1. Restrict Right Side");
printf("\n2. Restrict Left Side");
printf("\nEnter your Choice: ");
scanf("%d",&typ);
switch(typ)
{
case 1:
do
{
printf("\n1.Insert form Left ");
printf("\n2.Delete from left ");
printf("\n3.Delete form Right");
printf("\n4.display ");
printf("\n5.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter value :");
scanf("%d",&x);
insertl(x);
break;
case 2:
x=deletel();
printf("\n Deleted value is %d",x);
break;
case 3:
x=deleter();
printf("\n Deleted value is %d",x);
break;
case 4:
display();
break;
case 5:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=5);
break;
case 2:
do
{
printf("\n1.Insert form Right ");
printf("\n2.Delete from left ");
printf("\n3.Delete form Right ");
printf("\n4.display ");
printf("\n5.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter value :");
scanf("%d",&x);
insertr(x);
break;
case 2:
x=deletel();
printf("\n Deleted value is %d",x);
break;
case 3:
x=deleter();
printf("\n Deleted value is %d",x);
break;
case 4:
display();
break;
case 5:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=5);
break;

}
break;
case 2:
printf("\n1. Restrict Right side");
printf("\n2. Restrict Left Side");
printf("\nEnter your Choice: ");
scanf("%d",&typ);
switch(typ)
{
case 1:
do
{
printf("\n1.Insert form Right ");
printf("\n2.Insert form Left ");
printf("\n3.Delete from left ");
printf("\n4.display ");
printf("\n5.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter value :");
scanf("%d",&x);
insertr(x);
break;
case 2:
printf("\nEnter value :");
scanf("%d",&x);
insertl(x);
break;
case 3:
x=deletel();
printf("\n Deleted value is %d",x);
break;
case 4:
display();
break;
case 5:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=5);
break;
case 2:
do
{
printf("\n1.Insert form Right ");
printf("\n2.Insert form Left ");
printf("\n3.Delete form Right ");
printf("\n4.display ");
printf("\n5.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter value :");
scanf("%d",&x);
insertr(x);
break;
case 2:
printf("\nEnter value :");
scanf("%d",&x);
insertl(x);
break;
case 3:
x=deleter();
printf("\n Deleted value is %d",x);
break;
case 4:
display();
break;
case 5:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=5);
break;

}
break;
}
getch();
}

Friday, June 3, 2016

WAP to implement Double Ended Queue

 #include<stdio.h>
#include<conio.h>
int dq[5],r=-1,f=-1,r2=5,f2=5,max=5;
void insertr(int x)
{
if(r==max-1)
{
printf("Queue is full");
return;
}
r++;
dq[r]=x;
if(f==-1)
f=0;
r2=f;
f2=r;
}
int deletel()
{
int x;
if(f==-1)
{
printf("Queue is empty");
}
else
{
x=dq[f];
if(f==r)
{
f=r=-1;
f2=r2=max;
}
else
{
f++;
f2=r;
r2=f;
}
return x;
}
}
void insertl(int x)
{
if(r2==0)
{
printf("Queue is full");
return;
}
r2--;
dq[r2]=x;
if(f2==max)
f2=max-1;
r=f2;
f=r2;
}
int deleter()
{
int x;
if(f2==max)
{
printf("Queue is empty");
}
else
{
x=dq[f2];
if(f2==r2)
{
f=r=-1;
f2=r2=max;
}
else
{
f2--;
f=r2;
r=f2;
}
return x;
}
}
void display()
{
int i;
if(f==-1)
{
printf("\nQueue is empty");
return;
}
printf("\n Values in queue are:\n");
for(i=f;i<=r;i++)
{
printf("|%d| ",dq[i]);
}
}
void main()
{
int n,x;
clrscr();
do
{
printf("\n1.Insert form Right ");
printf("\n2.Insert form Left ");
printf("\n3.Delete from left ");
printf("\n4.Delete form Right ");
printf("\n5.display ");
printf("\n6.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter value :");
scanf("%d",&x);
insertr(x);
break;
case 2:
printf("\nEnter value :");
scanf("%d",&x);
insertl(x);
break;
case 3:
x=deletel();
printf("\n Deleted value is %d",x);
break;
case 4:
x=deleter();
printf("\n Deleted value is %d",x);
break;
case 5:
display();
break;
case 6:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=6);
getch();
}

Thursday, June 2, 2016

WAP to implement Circular Queue

#include<stdio.h>
#include<conio.h>
int cq[5],r=-1,f=-1,max=4;
void insert(int x)
{
if((r==max && f==0) || f==r+1)
{
printf("Queue is full");
return;
}
if(r==max)
r=0;
else
r++;
cq[r]=x;
if(f==-1)
f=0;
}
int del()
{
int x;
if(f==-1)
{
printf("Queue is empty");
}
else
{
x=cq[f];
if(f==r)
{
f=-1;
r=-1;
}
else
{
if(f==max)
f=0;
else
f++;
}
return x;
}
}
void display()
{
int i;
if(f==-1)
{
printf("Queue is empty");
return;
}
printf("\n Values in queue are:\n");
if(f<=r)
{
for(i=f;i<=r;i++)
{
printf("|%d| ",cq[i]);
}
}
else
{
for(i=f;i<=max;i++)
{
printf("|%d| ",cq[i]);
}
for(i=0;i<=r;i++)
{
printf("|%d| ",cq[i]);
}
}
}
void main()
{
int n,x;
clrscr();
do
{
printf("\n1.Insert ");
printf("\n2.delete ");
printf("\n3.display ");
printf("\n4.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter value :");
scanf("%d",&x);
insert(x);
break;
case 2:
x=del();
printf("\n Deleted value is %d",x);
break;
case 3:
display();
break;
case 4:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=4);
getch();
}

Wednesday, June 1, 2016

WAP to implement Queue of strings

#include<stdio.h>
#include<conio.h>
#include<string.h>
int r=-1,f=-1;
char sq[5][50];
void insert(char s[])
{
if(r==4)
{
printf("Queue is full");
return;
}
r++;
strcpy(sq[r],s);
if(f==-1)
f=0;
}
char* del()
{
char *x;
if(f==-1)
{
printf("Queue is empty");
}
else
{
strcpy(x,sq[f]);
if(f==r)
{
f=-1;
r=-1;
}
else
{
f++;
}
return x;
}
}
void display()
{
int i;
if(f==-1)
{
printf("Queue is empty");
return;
}
printf("\n Values in queue are:");
for(i=f;i<=r;i++)
{
printf("| %s | ",sq[i]);
}
}
void main()
{
int n,x;
char s[50];
clrscr();
do
{
printf("\n1.Insert ");
printf("\n2.delete ");
printf("\n3.display ");
printf("\n4.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter string :");
scanf("%s",s);
insert(s);
break;
case 2:
//*st=del();
printf("\n Deleted value is %s",del());
break;
case 3:
display();
break;
case 4:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=4);
getch();
}

Tuesday, May 31, 2016

WAP to implement Queue

#include<stdio.h>
#include<conio.h>
int q[5],r=-1,f=-1;
void insert(int x)
{
if(r==4)
{
printf("Queue is full");
return;
}
r++;
q[r]=x;
if(f==-1)
f=0;
}
int del()
{
int x;
if(f==-1)
{
printf("Queue is empty");
}
else
{
x=q[f];
if(f==r)
{
f=-1;
r=-1;
}
else
{
f++;
}
return x;
}
}
void display()
{
int i;
if(f==-1)
{
printf("No elements in Queue");
return;
}
printf("\n Values in queue are:\n");
for(i=f;i<=r;i++)
{
printf("|%d| ",q[i]);
}
}
void main()
{
int n,x;
clrscr();
do
{
printf("\n1.Insert ");
printf("\n2.delete ");
printf("\n3.display ");
printf("\n4.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter value :");
scanf("%d",&x);
insert(x);
break;
case 2:
x=del();
printf("\n Deleted value is %d",x);
break;
case 3:
display();
break;
case 4:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=4);
getch();
}

Monday, May 30, 2016

WAP to implement stack of strings

#include<stdio.h>
#include<conio.h>
#include<string.h>
int top=-1;
char st[10][50];
void push(char v[])
{
if(top==10)
printf("Stack is full");
else
{
top++;
strcpy(st[top],v);
}

}
char* pop()
{
char *s;
if(top==-1)
printf("\nstack is empty");
else
{
strcpy(s,st[top]);
top--;
}
return s;
}
void peep(int n)
{
if(n>top)
{
printf("Out of Range");
}
else
{
printf("Value at ps %d is %s",n,st[top-n+1]);
}
}
void change(int p,char v[])
{
if(p>top)
{
printf("Out of Range");
}
else
{
strcpy(st[top-p+1],v);
}
}
void display()
{
int i;
if(top==-1)
{
printf("Stack is empty");
return;
}
printf("\n displaying stack:");
for(i=top;i>=0;i--)
{
printf("\n%s",st[i]);
}
}
void main()
{
int n,p;
char v[50];
clrscr();
do
{
printf("\n1.Push\n ");
printf("2.Pop\n ");
printf("3.Peep\n ");
printf("4.Change\n ");
printf("5.Display\n ");
printf("6.Exit\n ");
printf("\nEnter your choice : ");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nenter a value :");
scanf("%s",&v);
push(v);
break;
case 2:
printf("Deleted value is: %s",pop());
break;
case 3:
printf("\nenter a positon :");
scanf("%d",&p);
peep(p);
break;
case 4:
printf("\nenter a postion :");
scanf("%d",&p);
printf("\nenter a value :");
scanf("%s",&v);
change(p,v);
break;
case 5:
display();
break;
case 6:
printf("\nThank you");
break;
default:
printf("\nYou have entered a wrong value");
}
}while(n!=6);
getch();
}

Sunday, May 29, 2016

WAP to implement stack with all its operations(push, pop, peep, change, display)

#include<stdio.h>
#include<conio.h>
int top=-1;
int st[10];
void push(int n)
{
if(top==10)
printf("Stack is full");
else
{
top++;
st[top]=n;
}

}
int pop()
{
int x;
if(top==-1)
printf("\nstack is empty");
else
{
x=st[top];
top--;
}
return x;
}
void peep(int n)
{
if(n>top)
{
printf("Out of Range");
}
else
{
printf("Value at ps %d is %d",n,st[top-n+1]);
}
}
void change(int p,int v)
{
if(p>top)
{
printf("Out of Range");
}
else
{
st[top-p+1]=v;
}
}
void display()
{
int i;
if(top==-1)
{
printf("Stack is empty");
return;
}
printf("\n displaying stack:");
for(i=top;i>=0;i--)
{
printf("\n%d",st[i]);
}
}
void main()
{
int n,v,p;
clrscr();
do
{
printf("\n1.Push\n ");
printf("2.Pop\n ");
printf("3.Peep\n ");
printf("4.Change\n ");
printf("5.Display\n ");
printf("6.Exit\n ");
printf("\nEnter your choice : ");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nenter a value :");
scanf("%d",&v);
push(v);
break;
case 2:
v=pop();
printf("delete number is: %d",v);
break;
case 3:
printf("\nenter a positon :");
scanf("%d",&p);
peep(p);
break;
case 4:
printf("\nenter a postion :");
scanf("%d",&p);
printf("\nenter a value :");
scanf("%d",&v);
change(v,p);
break;
case 5:
display();
break;
case 6:
printf("\nThank you");
break;
default:
printf("\nYou have entered a wrong value");
}
}while(n!=6);
getch();
}

Saturday, May 28, 2016

WAP to combine two sorted link list using merge sort

#include<stdio.h>
#include<conio.h>
struct node
{
int n;
struct node *next;
}*first=NULL,*first2=NULL,*first3=NULL,*temp,*temp1,*temp2,*temp3;
void insert(int x)
{
temp=(struct node*)malloc(sizeof(struct node));
temp->n=x;
if(first==NULL)
{
temp->next=NULL;
first=temp;
}
else
{
temp1=first;
while(temp1->next->n<x && temp1->next!=NULL)
{
temp1=temp1->next;
}
if(temp1==first && temp1->n>x)
{
temp->next=first;
first=temp;
}
else
{
temp->next=temp1->next;
temp1->next=temp;
}
}
}
void insert2(int x)
{
temp=(struct node*)malloc(sizeof(struct node));
temp->n=x;
if(first2==NULL)
{
temp->next=NULL;
first2=temp;
}
else
{
temp1=first2;
while(temp1->next->n<x && temp1->next!=NULL)
{
temp1=temp1->next;
}
if(temp1==first2 && temp1->n>x)
{
temp->next=first2;
first2=temp;
}
else
{
temp->next=temp1->next;
temp1->next=temp;
}
}
}
void display()
{
if(first==NULL)
{
printf("Stack is empty");
return;
}
temp=first;
while(temp!=NULL)
{
printf("\n%d",temp->n);
temp=temp->next;
}
}
void display2()
{
if(first2==NULL)
{
printf("Stack is empty");
return;
}
temp=first2;
while(temp!=NULL)
{
printf("\n%d",temp->n);
temp=temp->next;
}
}
void display3()
{
if(first3==NULL)
{
printf("Stack is empty");
return;
}
temp=first3;
while(temp!=NULL)
{
printf("\n%d",temp->n);
temp=temp->next;
}
}
void merge()
{
temp2=first;
temp3=first2;
while(temp2!=NULL && temp3!=NULL)
{
temp=(struct node*)malloc(sizeof(struct node));
if(temp2->n<temp3->n)
{
temp->n=temp2->n;
temp2=temp2->next;
}
else
{
temp->n=temp3->n;
temp3=temp3->next;
}
if(first3==NULL)
{
first3=temp;
}
else
{
temp1->next=temp;
}
temp1=temp;
temp->next=NULL;
}
while(temp2!=NULL)
{
temp=(struct node*)malloc(sizeof(struct node));
temp->n=temp2->n;
temp2=temp2->next;
temp1->next=temp;
temp1=temp;
temp->next=NULL;
}
while(temp3!=NULL)
{
temp=(struct node*)malloc(sizeof(struct node));
temp->n=temp3->n;
temp3=temp3->next;
temp1->next=temp;
temp1=temp;
temp->next=NULL;
}
}
void main()
{
int x;
char ch;
clrscr();
printf("\nEnter elements in list 1:\n");
do
{
printf("\nEnter a value: ");
scanf("%d",&x);
insert(x);
fflush(stdin);
display();
printf("\nDo you want to contiune(Y/N):");
scanf("%c",&ch);

}while(ch=='y' || ch=='Y');
printf("\nElements in list 1:\n");
display();
printf("\nEnter elements in list 2:\n");
do
{
printf("\nEnter a value: ");
scanf("%d",&x);
insert2(x);
fflush(stdin);
display2();
printf("\nDo you want to contiune(Y/N):");
scanf("%c",&ch);

}while(ch=='y' || ch=='Y');
printf("\nElements in list 2:\n");
display2();
merge();
printf("\nList after applying merge sort:\n")
display3();
getch();
}

Friday, May 27, 2016

WAP to Implement Merge sort

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,a[5],b[5],c[10],max=5,t;
clrscr();
printf("Enter list in sorted order:");
printf("\nEnter value in list 1:\n");
for(i=0;i<max;i++)
{
printf("Enter element %d: ",i+1);
scanf("%d",&a[i]);
}
printf("\nEnter value in list 2:\n");
for(i=0;i<max;i++)
{
printf("Enter element %d: ",i+1);
scanf("%d",&b[i]);
}
i=0;
j=0;
k=0;
while(i<max && j<max)
{
if(a[i]<b[j])
{
c[k]=a[i];
i++;
}
else
{
c[k]=b[j];
j++;
}
k++;
}
while(i<max)
{
c[k]=a[i];
k++;
i++;
}
while(j<max)
{
c[k]=b[j];
k++;
j++;
}
for(i=0;i<k;i++)
{
printf("\n%d",c[i]);
}
getch();
}

Thursday, May 26, 2016

WAP to implement bubble sort

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[10],max=10,t;
clrscr();
for(i=0;i<max;i++)
{
printf("Enter element %d: ",i);
scanf("%d",&a[i]);
}
for(i=0;i<max;i++)
{
for(j=0;j<max-1-i;j++)
{
//printf("\t%d<%d",a[j],a[j+1]);
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
for(i=0;i<max;i++)
{
printf("\n%d",a[i]);
}
getch();
}

Wednesday, May 25, 2016

WAP to implement Insertion sort.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[10],max=10,t;
clrscr();
for(i=0;i<max;i++)
{
printf("Enter element %d: ",i);
scanf("%d",&a[i]);
}
for(i=1;i<max;i++)
{
for(j=i-1;j>=0;j--)
{
//printf("\t%d<%d",a[j],a[j+1]);
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
else
break;
}
}
for(i=0;i<max;i++)
{
printf("\n%d",a[i]);
}
getch();
}

Tuesday, May 24, 2016

WAP to implement Selection sort.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[10],min,max=10,pos=0,t;
clrscr();
for(i=0;i<max;i++)
{
printf("Enter element %d: ",i);
scanf("%d",&a[i]);
}
for(i=0;i<max-1;i++)
{
min=a[i];
for(j=i+1;j<max;j++)
{
if(min>a[j])
{
min=a[j];
pos=j;
}
}
if(min!=a[i])
{
t=a[i];
a[i]=a[pos];
a[pos]=t;
}
}
for(i=0;i<max;i++)
{
printf("\n%d",a[i]);
}
getch();
}

Monday, May 23, 2016

WAP to implement multi link list of student record.

#include<stdio.h>
#include<conio.h>
struct marks
{
int subno,mrk;
struct marks *next;
}*mtemp,*mtemp1;
struct stud
{
int rno,tot;
float per;
struct marks *link;
struct stud *next;
}*first,*temp,*temp1;
void display()
{
if(first==NULL)
{
printf("No records");
return;
}
temp=first;
while(temp!=NULL)
{
printf("\nRollno : %d",temp->rno);
mtemp=temp->link;
while(mtemp!=NULL)
{
printf("\nSubno : %d\tmarks: %d",mtemp->subno,mtemp->mrk);
mtemp=mtemp->next;
}
printf("\nTotal : %d\tPercentage: %f%",temp->tot,temp->per);
temp=temp->next;
}

}
void main()
{
char mch,ch;
int cnt;
clrscr();
do
{
temp=(struct stud*)malloc(sizeof(struct stud));
printf("Enter rollno: ");
scanf("%d",&temp->rno);
temp->next=NULL;
temp->link=NULL;
cnt=0;
do
{
mtemp=(struct marks*)malloc(sizeof(struct marks));
printf("Enter subno: ");
scanf("%d",&mtemp->subno);
printf("Enter marks: ");
scanf("%d",&mtemp->mrk);
if(temp->link==NULL)
{
temp->link=mtemp;
temp->tot=mtemp->mrk;
}
else
{
mtemp1->next=mtemp;
temp->tot=temp->tot+mtemp->mrk;
}
mtemp->next=NULL;
mtemp1=mtemp;
cnt++;
fflush(stdin);
printf("\nDo you want Enter more sub marks: ");
scanf("%c",&mch);
}while(mch=='y' || mch=='Y');
temp->per=temp->tot/cnt;
if(first==NULL)
first=temp;
else
temp1->next=temp;
temp->next=NULL;
temp1=temp;
fflush(stdin);
printf("\nDo you want Enter more students: ");
scanf("%c",&ch);
}while(ch=='y' || ch=='Y');
display();
getch();
}

Sunday, May 22, 2016

WAP to implement doubly link list of various options of insert(beginning, end, at position, after node) and delete(beginning, end, at position, specific node)

#include<stdio.h>
#include<conio.h>
struct node
{
int rno;
char nm[50];
char gen;
int age;
struct node *next;
struct node *prev;
}*head,*temp,*temp1;
void insend(int r,char s[], char g,int a)
{
temp=(struct node*)malloc(sizeof(struct node)) ;
temp->rno=r;
strcpy(temp->nm,s);
temp->gen=g;
temp->age=a;
temp1=head->next;
while(temp1->next!=head)
{
temp1=temp1->next;
}
temp1->next=temp;
temp->prev=temp1;
temp->next=head;
}
void insatp(int r,char s[], char g,int a,int p)
{
int i;
temp=(struct node*)malloc(sizeof(struct node)) ;
temp->rno=r;
strcpy(temp->nm,s);
temp->gen=g;
temp->age=a;
temp1=head->next;
for(i=1;i<p-1 && temp1!=NULL;i++)
{
temp1=temp1->next;
}
if(temp1!=NULL)
{
temp->next=temp1->next;
temp1->next->prev=temp;
temp1->next=temp;
temp->prev=temp1;
}
}
void insaft(int r,char s[], char g,int a,int x)
{
temp=(struct node*)malloc(sizeof(struct node)) ;
temp->rno=r;
strcpy(temp->nm,s);
temp->gen=g;
temp->age=a;
temp1=head->next;
while(temp1->rno!=x  && temp1!=NULL)
{
temp1=temp1->next;
}
if(temp1!=NULL)
{
temp->next=temp1->next;
temp1->next->prev=temp;
temp1->next=temp;
temp->prev=temp1;
}
}
void insbeg(int r,char s[], char g,int a)
{
temp=(struct node*)malloc(sizeof(struct node)) ;
temp->rno=r;
strcpy(temp->nm,s);
temp->gen=g;
temp->age=a;
if(head->next==NULL)
{
head->next=temp;
temp->next=head;
head->prev=temp;
}
else
{
temp->next=head->next;
temp->next->prev=temp;
head->next=temp;
}
temp->prev=head;
}
void delfirst()
{
temp=head->next;
head->next=temp->next;
temp->next->prev=head;

}
void delend()
{
temp=head->next;
while(temp->next->next!=head)
{
temp=temp->next;
}
temp->next=head;
}
void delnode(int x)
{
temp=head->next;
while(temp->next->rno!=x && temp1!=NULL)
{
temp=temp->next;
}
if(temp!=NULL)
{
temp->next=temp->next->next;
temp->next->prev=temp;
}
else
printf("\nNot Found");
}
void delatp(int p)
{
int i;
temp=head->next;
for(i=1;i<p-1 && temp!=NULL;i++)
{
temp=temp->next;
}
if(temp!=NULL)
{
temp->next=temp->next->next;
temp->next->prev=temp;
}
else
printf("\nNot Found");
}
void display()
{
temp=head->next;
do
{
printf("\n|Rollno: %d| ",temp->rno);
printf(" |Name: %s| ",temp->nm);
printf(" |Gender: %c| ",temp->gen);
printf(" |Age: %d| ",temp->age);
temp=temp->next;
}while(temp!=head);
getch();
}
void main()
{
int n,r,a,ch,p,x;
char s[50],g;
clrscr();
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
do
{
printf("\n1.Insert ");
printf("\n2.delete ");
printf("\n3.display ");
printf("\n4.exit");
printf("\nEnter your choice :");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\nEnter rollno: ");
scanf("%d",&r);
fflush(stdin);
printf("Enter name: ");
gets(s);
printf("Enter gender(m/f): ");
scanf("%c",&g);
printf("Enter age: ");
scanf("%d",&a);
printf("\nSelect Option");
printf("\n1.Insert at Begining");
printf("\n2.Insert at Postion");
printf("\n3.Insert after Rollno");
printf("\n4.Insert at End");
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
insbeg(r,s,g,a);
break;
case 2:
printf("\nEnter Position:");
scanf("%d",&p);
insatp(r,s,g,a,p);
break;
case 3:
printf("Enter Rollno:");
scanf("%d",&x);
insaft(r,s,g,a,x);
break;
case 4:
insend(r,s,g,a);
break;
}

break;
case 2:
printf("\nSelect Option");
printf("\n1.Delete at Begining");
printf("\n2.Delete at Postion");
printf("\n3.Delete Rollno");
printf("\n4.Delete at End");
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
delfirst();
break;
case 2:
printf("\nEnter Position:");
scanf("%d",&p);
delatp(p);
break;
case 3:
printf("Enter Rollno:");
scanf("%d",&x);
delnode(x);
break;
case 4:
delend();
break;
}
printf("\n Value Deleted ");
break;
case 3:
display();
break;
case 4:
printf("\nThank you");
break;
default:
printf("\nInvalid choice");
}

}while(n!=4);
}