Program for Bsc Computer Department



Program#1>
/* Write a C program to implement integer stack with operation: push, pop, peep
& change */


#include<stdio.h>
#include<conio.h>
#define N 3
struct stack
{
int s[N];
int top;
};
void push(int[],int*,int);
int pop(int[],int*);
int peep(int[],int,int);
void change(int[],int,int,int);
void display(int[],int);
void main()
{
int ch,x,i;
struct stack s1;
s1.top=-1;
clrscr();
while(1)
{
   printf("\n\tMENU\n1.PUSH\n2.POP\n3.PEEP\n4.CHANGE\n5.DISPLAY\n6.EXIT");
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter Element:");
scanf("%d",&x);
push(s1.s,&s1.top,x);
break;
case 2:
x=pop(s1.s,&s1.top);
if(x!=0)
{
printf("\nElement poped=%d",x);
}
break;
case 3:
printf("\nEnter position:");
scanf("%d",&i);
x=peep(s1.s,s1.top,i);
if(x!=0)
{
printf("\nElement peeped=%d",x);
}
break;
case 4:
printf("\nEnter position:");
scanf("%d",&i);
printf("\nEnter new Element:");
scanf("%d",&x);
change(s1.s,s1.top,i,x);
break;
       case 5:
display(s1.s,s1.top);
break;
       case 6:
exit(0);
}
}
}
void push(int s[],int*top,int x)
{
if(*top>=N-1)
{
printf("\nSTACK OVERFLOW....!!");
return;
}
*top=*top+1;
s[*top]=x;
}
int pop(int s[],int *top)
{
int y;
if(*top==-1)
{
printf("\nSTACK UNDERFLOW....!!");
return(0);
}
y=s[*top];
*top=*top-1;
return(y);
}
int peep(int s[],int top,int i)
{
if(top-i+1<=-1)
{
printf("\nSTACK UNDERFLOW ON PEEP....!!");
return(0);
}
return(s[top-i+1]);
}
void change(int s[],int top,int i,int x)
{
if(top-i+1<=-1)
{
printf("\nSTRACK UNDERFLOW FOR CHANGE....!!");
return;
}
s[top-i+1]=x;
}
void display(int s[],int top)
{
int i;
printf("\nCONTENTS OF STACK");
for(i=top;i>=0;i--)
{
printf("\n%d",s[i]);
}
}
/*******************************************OUTPUT*********************************************
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:1

Enter Element:11

MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:1

Enter Element:22

MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:1

Enter Element:33

MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:1

Enter Element:44

STACK OVERFLOW....!!

MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:5

CONTENTS OF STACK
33
22
11
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:3

Enter position:2

Element peeped=22
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:4

Enter position:3

Enter new Element:44
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:5

CONTENTS OF STACK
33
22
44
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:2

Element poped=33
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:2

Element poped=22
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:2

Element poped=44
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:2

STACK UNDERFLOW....!!
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:6
**********************************************************************************************/






Program#2

/* Write a C program to implement character stack with operation: push, pop, peep & change */


#include<stdio.h>
#include<conio.h>
#define N 3
struct stack
{
char s[N];
int top;
};
void push(char[],int*,char);
char pop(char[],int*);
char peep(char[],int,int);
void change(char[],int,int,char);
void display(char[],int);
void main()
{
int ch,i;
char x;
struct stack s1;
s1.top=-1;
clrscr();
while(1)
{
  printf("\n\tMENU\n1.PUSH\n2.POP\n3.PEEP\n4.CHANGE\n5.DISPLAY\n6.EXIT");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter Character: ");
flushall();
scanf("%c",&x);
push(s1.s,&s1.top,x);
break;
case 2:
x=pop(s1.s,&s1.top);
if(x!=0)
{
printf("\nCharacter poped= %c",x);
}
break;
case 3:
printf("\nEnter position:");
scanf("%d",&i);
x=peep(s1.s,s1.top,i);
if(x!=0)
{
printf("\nCharacter peeped= %c",x);
}
break;
case 4:
printf("\nEnter position: ");
scanf("%d",&i);
printf("\nEnter new Character: ");
flushall();
scanf("%c",&x);
change(s1.s,s1.top,i,x);
break;
       case 5:
display(s1.s,s1.top);
break;
       case 6:
exit(0);
}
}
}
void push(char s[],int*top,char x)
{
if(*top>=N-1)
{
printf("\nSTACK OVERFLOW....!!");
return;
}
*top=*top+1;
s[*top]=x;
}
char pop(char s[],int *top)
{
char y;
if(*top==-1)
{
printf("\nSTACK UNDERFLOW....!!");
return(0);
}
y=s[*top];
*top=*top-1;
return(y);
}
char peep(char s[],int top,int i)
{
if(top-i+1<=-1)
{
printf("\nSTACK UNDERFLOW ON PEEP....!!");
return(0);
}
return(s[top-i+1]);
}
void change(char s[],int top,int i,char x)
{
if(top-i+1<=-1)
{
printf("\nSTRACK UNDERFLOW FOR CHANGE....!!");
return;
}
s[top-i+1]=x;
}
void display(char s[],int top)
{
int i;
printf("\nCONTENTS OF STACK");
for(i=top;i>=0;i--)
{
printf("\n%c",s[i]);
}
}
/*****************************************OUTPUT***********************************************
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:1

Enter Character:a

MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:1

Enter Character:b

MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:1

Enter Element:c

MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:1

Enter Character:d

STACK OVERFLOW....!!
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:5

CONTENTS OF STACK
c
b
a
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:3

Enter position:2

Character peeped=b
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:4

Enter position:3

Enter new Character:f
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:5

CONTENTS OF STACK
c
b
f
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:2

Character poped=c
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:2

Character poped=b
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:2

Character poped=f
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:2

STACK UNDERFLOW....!!
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:6
********************************************************************************************/



Program#3

/* Write a C program to implement string stack with operation: push & pop */

#include<stdio.h>
#include<string.h>
#include<conio.h>
#define N 3
struct stack
{
char s[N][15];
int top;
};
void push(char[][15],int*,char[15]);
void pop(char[][15],int*);
void display(char[][15],int);
void main()
{
int ch,i;
char x[15];
struct stack s1;
s1.top=-1;
clrscr();
while(1)
{
printf("\n\tMENU\n1.PUSH\n2.POP\n3.DISPLAY\n4.EXIT");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter String: ");
flushall();
scanf("%s",&x);
push(s1.s,&s1.top,x);
break;
case 2:
pop(s1.s,&s1.top);
break;
case 3:
display(s1.s,s1.top);
break;
       case 4:
exit(0);
}
}
}
void push(char s[][15],int*top,char x[15])
{
if(*top>=N-1)
{
printf("\nSTACK OVERFLOW....!!");
return;
}
*top=*top+1;
strcpy(s[*top],x);
}
void pop(char s[][15],int *top)
{
char y[15];
if(*top==-1)
{
printf("\nSTACK UNDERFLOW....!!");
return;
}
strcpy(y,s[*top]);
*top=*top-1;
printf("\nString poped= %s",y);
}
void display(char s[][15],int top)
{
int i;
printf("\nCONTENTS OF STACK");
for(i=top;i>=0;i--)
{
printf("\n%s",s[i]);
}
}
/******************************************OUTPUT**********************************************
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice: 1

Enter String: chetan

MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice: 1

Enter String: manish

MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice: 1

Enter Element: akash

MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice: 1

Enter String: vaibhav

STACK OVERFLOW....!!

MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice: 3

CONTENTS OF STACK
akash
manish
chetan

MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice: 2

String poped= akash

MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice:2

String poped= manish
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice: 2

String poped= chetan
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice: 2

STACK UNDERFLOW....!!
MENU
1.PUSH
2.POP
3.PEEP
4.CHANGE
5.DISPLAY
6.EXIT
Enter your choice: 4
**************************************************************************************************/



























Program#4  

/* Write a program to convert given infix to postfix expression */

#include<stdio.h>
#include<conio.h>
#define N 10
struct stack
{
char s[N];
int top;
};
void push(char[],int*,char);
char pop(char[],int*);
void intopost(char[]);
int prt(char x)
{
switch(x)
{
case '(':
return(0);
case '+':
case '-':
return(1);
case '*':
case '/':
case '%':
return(2);
case '$':
return(3);
}
}
void main()
{
char infix[20];
clrscr();
printf("\nEnter infix expression: ");
gets(infix);
intopost(infix);
getch();
}
void push(char s[],int*top,char x)
{
if(*top>=N-1)
{
printf("\nSTACK OVERFLOW....!!");
return;
}
*top=*top+1;
s[*top]=x;
}
char pop(char s[],int *top)
{
char y;
if(*top==-1)
{
printf("\nSTACK UNDERFLOW....!!");
return(0);
}
y=s[*top];
*top=*top-1;
return(y);
}
void intopost(char infix[])
{
struct stack opstack;
char ch,postfix[20];
int i=0,j=0;
opstack.top=-1;
while((ch=infix[i])!='\0')
{
i++;
if(isalpha(ch))
{
postfix[j]=ch;
j++;
}
else if(ch=='(')
{
push(opstack.s,&opstack.top,ch);
}
else if(ch==')')
{
ch=pop(opstack.s,&opstack.top);
while(ch!='('&&opstack.top!=-1)
{
postfix[j]=ch;
j++;
ch=pop(opstack.s,&opstack.top);
}
}
else
{
while(opstack.top!=-1&&prt(opstack.s[opstack.top])>=prt(ch))
{
postfix[j]=pop(opstack.s,&opstack.top);
j++;
}
push(opstack.s,&opstack.top,ch);
}
}
while(opstack.top!=-1)
{
postfix[j]=pop(opstack.s,&opstack.top);
j++;
}
postfix[j]='\0';
printf("\nPostfix String= %s",postfix);
}
/*******************************************OUTPUT******************************************

Enter infix expression: (a+b)*(c-d)/f%g$x

Postfix String= ab+cd-*f/gx$%
***********************************************************************************************/















































Program#1  

/* Write a program to implement integer Queue with its operation.*/

#include<stdio.h>
#include<conio.h>
#define N 3
struct Queue
{
int q[N],a,b;
};
void Qinsert(int[],int*,int*,int);
int Qdelete(int[],int*,int*);
void display(int[],int,int);
void main()
{
struct Queue q1;
int ch,x;
q1.a=-1;
q1.b=-1;
clrscr();
while(1)
{
printf("\n\tMENU\n1.INSERT\n2.DELETE\n3.DISPLAY\n4.EXIT");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter the element: ");
scanf("%d",&x);
Qinsert(q1.q,&q1.a,&q1.b,x);
break;
case 2:
x=Qdelete(q1.q,&q1.a,&q1.b);
if(x!=-1)
printf("\nElement deleted= %d",x);
break;
case 3:
display(q1.q,q1.a,q1.b);
break;
case 4:
exit(0);
}
}
}
void Qinsert(int q[],int *a,int *b,int x)
{
if(*b>=N-1)
{
printf("\nQUEUE OVERFLOW....!");
return;
}
*b=*b+1;
q[*b]=x;
if(*a==-1)
{
*a=0;
}
}
int Qdelete(int q[],int *a,int *b)
{
int x;
if(*a<=-1)
{
printf("\nQUEUE UNDERFLOW...!");
return(-1);
}
x=q[*a];
if(*a==*b)
*a=*b=-1;
else
*a=*a+1;
return(x);
}
void display(int q[],int a,int b)
{
int i;
if(b!=-1)
{
printf("\nCONTENTS OF QUEUE:\n");
for(i=a;i<=b;i++)
{
printf("%d\t",q[i]);
}
}
else
printf("\nEMPTY QUEUE....");
}
/******************************************OUTPUT**********************************************
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter the element: 21

MENU
1.INSERT
2.DELETE
3.DISPLAY
.EXIT
Enter your choice: 1

Enter the element: 22

MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter the element: 23

MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter the element: 24

QUEUE OVERFLOW....!
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 3

CONTENTS OF QUEUE:
21      22      23
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 21
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 22
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 23
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 2

QUEUE UNDERFLOW...!
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 4
**************************************************************************************************/









































Program#1  

/* Write a program to implement character Queue with its operation.*/

#include<stdio.h>
#include<conio.h>
#define N 3
struct Queue
{
char q[N];
int f,r;
};
void Qinsert(char[],int*,int*,char);
char Qdelete(char[],int*,int*);
void display(char[],int,int);
void main()
{
struct Queue q1;
int ch;
char x;
q1.f=-1;
q1.r=-1;
clrscr();
while(1)
{
printf("\n\tMENU\n1.INSERT\n2.DELETE\n3.DISPLAY\n4.EXIT");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter the character: ");
flushall();
scanf("%c",&x);
Qinsert(q1.q,&q1.f,&q1.r,x);
break;
case 2:
x=Qdelete(q1.q,&q1.f,&q1.r);
if(x!=-1)
printf("\nCharacter deleted= %c",x);
break;
case 3:
display(q1.q,q1.f,q1.r);
break;
case 4:
exit(0);
}
}
}
void Qinsert(char q[],int *f,int *r,char x)
{
if(*r>=N-1)
{
printf("\nQUEUE OVERFLOW....!");
return;
}
*r=*r+1;
q[*r]=x;
if(*f==-1)
{
*f=0;
}
}
char Qdelete(char q[],int *f,int *r)
{
int x;
if(*f<=-1)
{
printf("\nQUEUE UNDERFLOW....!");
return(-1);
}
x=q[*f];
if(*f==*r)
*f=*r=-1;
else
*f=*f+1;
return(x);
}
void display(char q[],int f,int r)
{
int i;
if(r!=-1)
{
printf("\nCONTENTS OF QUEUE\n");
for(i=f;i<=r;i++)
{
printf("%c\t",q[i]);
}
}
else
printf("\nEMPTY QUEUE....");
}
/*******************************************OUTPUT********************************************
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter the character: a

MENU
1.INSERT
2.DELETE
3.DISPLAY
.EXIT
Enter your choice: 1

Enter the character: b

MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter the character: c

MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter the character: d

QUEUE OVERFLOW....!
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 3

CONTENTS OF QUEUE:
a b c
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 2

Character deleted= a
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 2

Character deleted= b
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 2

Character deleted= c
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 2

QUEUE UNDERFLOW...!
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 4
**************************************************************************************************/






































Program#3  

/* Write a program to implement Circular Queue to store integer elements
with its operation*/

#include<stdio.h>
#include<conio.h>
#define N 3
struct Queue
{
int q[N];
int f,r;
};
void CQinsert(int[],int*,int*,int);
int CQdelete(int[],int*,int*);
void display(int[],int,int);
void main()
{
struct Queue q1;
int ch,y;
q1.f=-1;
q1.r=-1;
clrscr();
while(1)
{
printf("\n\tMENU\n1.INSERT\n2.DELETE\n3.DISPLAY\n4.EXIT");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter the element: ");
scanf("%d",&y);
CQinsert(q1.q,&q1.f,&q1.r,y);
break;
case 2:
y=CQdelete(q1.q,&q1.f,&q1.r);
if(y!=-1)
printf("\nElement deleted= %d",y);
break;
case 3:
display(q1.q,q1.f,q1.r);
break;
case 4:
exit(0);
}
}
}
void CQinsert(int q[],int *f,int *r,int y)
{
if(*r==N-1)
*r=0;
else
*r=*r+1;
if(*f==*r)
{
printf("\nQUEUE OVERFLOW....!!");
if(*r==0)
*r=N-1;
else
*r=*r-1;
return;
}
q[*r]=y;
if(*f==-1)
*f=0;
}
int CQdelete(int q[],int *f,int *r)
{
int y;
if(*f==-1)
{
printf("\nQUEUE UNDERFLOW...!!");
return(0);
}
y=q[*f];
if(*f==*r)
{
*f=*r=0;
return(y);
}
if(*f==N-1)
*f=0;
else
*f=*f+1;
return(y);
}
void display(int q[],int f,int r)
{
int i;
printf("\nCONTENTS OF QUEUE\n");
for(i=f;i<=N-1;i++)
printf("%d\t",q[i]);
if(f>r)
{
for(i=0;i<=r;i++)
printf("%d\t",q[i]);
}
}
/******************************************OUTPUT********************************************
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter the element: 11
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter the element: 22

MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter the element: 33

MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter the element: 44

QUEUE OVERFLOW....!!
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 3

CONTENTS OF QUEUE
11      22      33
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 11
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 22

MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 33
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 11
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 4
*************************************************************************************************/





                                                                                

























Program#4  

/* write a program to implement Circular Queue to store character elements
with its operation. */

#include<stdio.h>
#include<conio.h>
#define N 3
struct Queue
{
char q[N];
int f,r;
};
void CQinsert(char[],int*,int*,char);
char CQdelete(char[],int*,int*);
void display(char[],int,int);
void main()
{
struct Queue q1;
int ch;
char y;
q1.f=-1;
q1.r=-1;
clrscr();
while(1)
{
printf("\n\tMENU\n1.INSERT\n2.DELETE\n3.DISPLAY\n4.EXIT");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter the character: ");
flushall();
scanf("%c",&y);
CQinsert(q1.q,&q1.f,&q1.r,y);
break;
case 2:
y=CQdelete(q1.q,&q1.f,&q1.r);
if(y!=-1)
printf("\nCharacter deleted= %c",y);
break;
case 3:
display(q1.q,q1.f,q1.r);
break;
case 4:
exit(0);
}
}
}
void CQinsert(char q[],int *f,int *r,char y)
{
if(*r==N-1)
*r=0;
else
*r=*r+1;
if(*f==*r)
{
printf("\nQUEUE OVERFLOW....!!");
if(*r==0)
*r=N-1;
else
*r=*r-1;
return;
}
q[*r]=y;
if(*f==-1)
*f=0;
}
char CQdelete(char q[],int *f,int *r)
{
char y;
if(*f==-1)
{
printf("\nQUEUE UNDERFLOW...!!");
return(0);
}
y=q[*f];
if(*f==*r)
{
*f=*r=0;
return(y);
}
if(*f==N-1)
*f=0;
else
*f=*f+1;
return(y);
}
void display(char q[],int f,int r)
{
int i;
printf("\nCONTENTS OF QUEUE\n");
for(i=f;i<=N-1;i++)
printf("%c\t",q[i]);
if(f>r)
{
for(i=0;i<=r;i++)
printf("%c\t",q[i]);
}
}
/***************************************OUTPUT*********************************************
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter the character: a

MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter the character: b
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter the character: c

MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 1  

Enter the character: d

QUEUE OVERFLOW....!!
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 3

CONTENTS OF QUEUE
a       b       c
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 2

deleted character= a
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 2

deleted character= b
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 2

deleted character= c
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 2

deleted character= a
MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice: 4
***************************************************************************************************/































Program#1  

/* write a program to implement singly linked list to store integer elements
with its operation- first insert, first delete */

#include<stdio.h>
#include<conio.h>
typedef struct node
{
int info;
struct node *link;
}NODE;
NODE* insfirst(NODE*,int);
NODE* delfirst(NODE*);
void display(NODE*);
void main()
{
int ch,a;
NODE *first;
first=NULL;
clrscr();
while(1)
{
printf("\n\tMENU\n1.INSERT FIRST\n2.DELETE FIRST\n3.DISPLAY\n4.EXIT");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter element: ");
scanf("%d",&a);
first=insfirst(first,a);
break;
case 2:
first=delfirst(first);
break;
case 3:
display(first);
break;
case 4:
exit(0);
}
}
}
NODE* insfirst(NODE *first,int x)
{
NODE *NEW;
NEW=(NODE*)malloc(sizeof(NODE));
NEW->info=x;
NEW->link=first;
return(NEW);
}
NODE* delfirst(NODE *first)
{
if(first==NULL)
{
printf("\nLINKED LIST UNDERFLOW....!!");
return(first);
}
printf("\nElement deleted= %d",first->info);
first=first->link;
return(first);
}
void display(NODE *first)
{
NODE *SAVE;
SAVE=first;
printf("\nCONTENTS OF LINKED LIST\n");
while(SAVE!=NULL)
{
printf("%d\t",SAVE->info);
SAVE=SAVE->link;
}
}
/****************************************OUTPUT************************************************
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 11

MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 22

MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 33

MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 44

MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 55

MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 3

CONTENTS OF LINKED LIST
55      44      33      22      11
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 55
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 44
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 33
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 22
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 11
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

LINKED LIST UNDERFLOW....!!
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 4
************************************************************************************************/































Program#2  

/* write a program to implement singly linked list to store String elements
with its operation- first insert, first delete*/

#include<stdio.h>
#include<conio.h>
typedef struct node
{
char info[10];
struct node *link;
}NODE;
NODE* insfirst(NODE*,char[10]);
NODE* delfirst(NODE*);
void display(NODE*);
void main()
{
int ch;
char a[10];
NODE *first;
first=NULL;
clrscr();
while(1)
{
printf("\n\tMENU\n1.INSERT FIRST\n2.DELETE FIRST\n3.DISPLAY\n4.EXIT");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter String: ");
scanf("%s",&a);
first=insfirst(first,a);
break;
case 2:
first=delfirst(first);
break;
case 3:
display(first);
break;
case 4:
exit(0);
}
}
}
NODE* insfirst(NODE *first,char x[])
{
NODE *NEW;
NEW=(NODE*)malloc(sizeof(NODE));
strcpy(NEW->info,x);
NEW->link=first;
return(NEW);
}
NODE* delfirst(NODE *first)
{
if(first==NULL)
{
printf("\nLINKED LIST UNDERFLOW....!!");
return(first);
}
printf("\nString deleted= %s",first->info);
first=first->link;
return(first);
}
void display(NODE *first)
{
NODE *SAVE;
SAVE=first;
printf("\nCONTENTS OF LINKED LIST\n");
while(SAVE!=NULL)
{
printf("%s\t",SAVE->info);
SAVE=SAVE->link;
}
}
/*****************************************OUTPUT*********************************************
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter String: vaibhav

MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter String: chetan

MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter String: manish

MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter String: akash

MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter String: ram

MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 3

CONTENTS OF LINKED LIST
ram     akash   manish  chetan  vaibhav
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

String deleted= ram
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

String deleted= akash
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

String deleted= manish
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

String deleted= chetan
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

String deleted= vaibhav
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

LINKED LIST UNDERFLOW....!!
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 4
***********************************************************************************************/






























Program#3

/* write a c program to implement singly linked list with its operation- middle insert, middle delete*/

#include<stdio.h>
#include<conio.h>
typedef struct node
{
int info;
struct node *link;
}NODE;
NODE* insmiddle(NODE*,int,int);
NODE* delmiddle(NODE*,int);
void display(NODE*);
void main()
{
int ch,a,p;
NODE *first=NULL;
clrscr();
while(1)
{
printf("\n\tMENU\n1.INSERT MIDDLE\n2.DELETE MIDDLE\n3.DISPLAY\n4.EXIT");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter element: ");
scanf("%d",&a);
printf("\nEnter the node number: ");
scanf("%d",&p);
first=insmiddle(first,a,p);
break;
case 2:
printf("\nEnter the node number: ");
scanf("%d",&p);
first=delmiddle(first,p);
break;
case 3:
display(first);
break;
case 4:
exit(0);
}
}
}
NODE* insmiddle(NODE*first,int x,int k)
{
int count=1;
NODE*NEW;
NODE*SAVE;
NODE*PRED;
NEW=(NODE*)malloc(sizeof(NODE*));
NEW->info=x;
if(k==1)
{
NEW->link=first;
return(NEW);
}
SAVE=first;
while(SAVE!=NULL&&count!=k)
{
PRED=SAVE;
SAVE=SAVE->link;
count=count+1;
}
if(SAVE!=NULL)
{
NEW->link=PRED->link;
PRED->link=NEW;
return(first);
}
else
printf("\nINSERTION IS NOT POSSIBLE");
return(first);
}
NODE*delmiddle(NODE*first,int k)
{
int count=1;
NODE*SAVE;
NODE*PRED;
if(first==NULL)
{
printf("\nLINK LIST UNDERFLOW...!");
return(NULL);
}
if(k==1)
{
printf("\nDeleted Element:%d",first->info);
return(first->link);
}
SAVE=first;
while(count!=k&&SAVE!=NULL)
{
PRED=SAVE;
SAVE=SAVE->link;
count=count+1;
}
if(SAVE!=NULL)
{
printf("\nDeleted Element:%d",SAVE->info);
PRED->link=SAVE->link;
}
else
printf("\nNODE NOT FOUND...!");
return(first);
}
void display(NODE *first)
{
NODE *NEW;
NEW=first;
if(first==NULL)
{
printf("\nLINKED lIST EMPTY...!");
return;
}
printf("\nCONTENTS OF LINKED LIST\n");
while(NEW!=NULL)
{
printf("%d\t",NEW->info);
NEW=NEW->link;
}
}
/*****************************************OUTPUT***********************************************

MENU
1.INSERT MIDDLE
2.DELETE MIDDLE
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 11

Enter the node number: 1

MENU
1.INSERT MIDDLE
2.DELETE MIDDLE
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 22

Enter the node number: 1

MENU
1.INSERT MIDDLE
2.DELETE MIDDLE
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 33

Enter the node number: 2

MENU
1.INSERT MIDDLE
2.DELETE MIDDLE
3.DISPLAY
4.EXIT
Enter your choice: 3

CONTENTS OF LINKED LIST
22      33      11
MENU
1.INSERT MIDDLE
2.DELETE MIDDLE
3.DISPLAY
4.EXIT
Enter your choice: 2

Enter the node number: 1

Deleted Element:22
MENU
1.INSERT MIDDLE
2.DELETE MIDDLE
3.DISPLAY
4.EXIT
Enter your choice: 2

Enter the node number: 4

NODE NOT FOUND...!
MENU
1.INSERT MIDDLE
2.DELETE MIDDLE
3.DISPLAY
4.EXIT
Enter your choice: 4
***********************************************************************************************/




















Program#4

/* Write a c program to implement singly linked list to with its operation- last insert, last delete */

#include<stdio.h>
#include<conio.h>
typedef struct node
{
int info;
struct node *link;
}NODE;
NODE* inslast(NODE*,int);
NODE* dellast(NODE*);
void display(NODE*);
void main()
{
int ch,a;
NODE *first;
first=NULL;
clrscr();
while(1)
{
printf("\n\tMENU\n1.INSERT LAST\n2.DELETE LAST\n3.DISPLAY\n4.EXIT");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter element: ");
scanf("%d",&a);
first=inslast(first,a);
break;
case 2:
first=dellast(first);
break;
case 3:
display(first);
break;
case 4:
exit(0);
}
}
}
NODE* inslast(NODE *first,int x)
{
NODE *NEW;
NODE* SAVE;
NEW=(NODE*)malloc(sizeof(NODE));
NEW->info=x;
NEW->link=NULL;
if(first==NULL)
return(NEW);
SAVE=first;
while(SAVE->link!=NULL)
{
SAVE=SAVE->link;
}
SAVE->link=NEW;
return(first);
}
NODE* dellast(NODE *first)
{
NODE*SAVE;
NODE*PRED;
if(first==NULL)
{
printf("\nLINKED LIST UNDERFLOW....!!");
return(NULL);
}
if(first->link==NULL)
{
printf("\nElement deleted= %d",first->info);
return(NULL);
}
SAVE=first;
while(SAVE->link!=NULL)
{
PRED=SAVE;
SAVE=SAVE->link;
}
PRED->link=NULL;
printf("\nElement deleted= %d",SAVE->info);
return(first);
}
void display(NODE *first)
{
NODE *NEW;
NEW=first;
if(first==NULL)
{
printf("\nLINKED LIST EMPTY");
return;
}
while(NEW!=NULL)
{
printf("%d\t",NEW->info);
NEW=NEW->link;
}
}
/******************************************OUTPUT**********************************************
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 11

MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 22

MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 33

MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 44

MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 55

MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 3

CONTENTS OF LINKED LIST
11      22      33      44      55
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 55
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 44
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 33
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 22
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 11
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 2

LINKED LIST UNDERFLOW....!!
MENU
1.INSERT FIRST
2.DELETE FIRST
3.DISPLAY
4.EXIT
Enter your choice: 4
**********************************************************************************************/





Program#5  

/* Write a program to search an element, reverse a linked list and make a copy
of singly linked list */

#include<stdio.h>
#include<conio.h>
typedef struct node
{
int info,field;
struct node *link,*ptr;
}NODE;
NODE* insert(NODE *first,int x)
{
NODE *NEW;
NEW=(NODE*)malloc(sizeof(NODE));
NEW->info=x;
NEW->link=first;
return(NEW);
}
NODE* search(NODE *first,int x)
{
NODE *SAVE;
SAVE=first;
while(SAVE!=NULL)
{
if(SAVE->info==x)
return(SAVE);
else
SAVE=SAVE->link;
}
return(NULL);
}
NODE *copy(NODE *first)
{
NODE *TEMP,*NEW,*SAVE,*BEGIN;
if(first==NULL)
return(NULL);
NEW->field=first->info;
BEGIN=NEW;
SAVE=first;
while(SAVE->link!=NULL)
{
TEMP=NEW;
SAVE=SAVE->link;
NEW=(NODE*)malloc(sizeof(NODE));
NEW->field=SAVE->info;
TEMP->ptr=NEW;
}
NEW->ptr=NULL;
printf("\nLINKED LIST COPIED....");
return(BEGIN);
}
NODE* reverse(NODE *first)
{
NODE *TEMP,*SAVE,*PRED;
if(first==NULL)
{
printf("\nLINKED LIST UNDERFLOW....!!");
return(first);
}
TEMP=first;
SAVE=NULL;
while(TEMP!=NULL)
{
PRED=SAVE;
SAVE=TEMP;
TEMP=TEMP->link;
SAVE->link=PRED;
}
printf("\nLINKED LIST REVERSED....");
return(SAVE);
}
void display(NODE *first)
{
NODE *SAVE;
printf("\nCONTENTS OF LINKED LIST\n");
SAVE=first;
while(SAVE!=NULL)
{
printf("%d\t",SAVE->info);
SAVE=SAVE->link;
}
}
void main()
{
int ch,a;
NODE *first,*p;
clrscr();
first=NULL;
while(1)
{
printf("\n\tMENU\n1.INSERT ELEMENT\n2.SEARCH\n3.COPY\n4.REVERSE\n5.DISPLAY\n6.EXIT");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter element: ");
scanf("%d",&a);
first=insert(first,a);
break;
case 2:
printf("\nEnter element: ");
scanf("%d",&a);
p=search(first,a);
if(p!=NULL)
printf("\nSuccessfull search....");
else
printf("\nUnsuccessful search....");
break;
case 3:
first=copy(first);
break;
case 4:
first=reverse(first);
break;
case 5:
display(first);
break;
case 6:
exit(0);
}
}
}
/*******************************************OUTPUT******************************************
MENU
1.INSERT ELEMENT
2.SEARCH
3.COPY
4.REVERSE
5.DISPLAY
6.EXIT
Enter your choice: 1

Enter element: 11

MENU
1.INSERT ELEMENT
2.SEARCH
3.COPY
4.REVERSE
5.DISPLAY
6.EXIT
Enter your choice: 1

Enter element: 22

MENU
1.INSERT ELEMENT
2.SEARCH
3.COPY
4.REVERSE
5.DISPLAY
6.EXIT
Enter your choice: 1

Enter element: 33

MENU
1.INSERT ELEMENT
2.SEARCH
3.COPY
4.REVERSE
5.DISPLAY
6.EXIT
Enter your choice: 1

Enter element: 44

MENU
1.INSERT ELEMENT
2.SEARCH
3.COPY
4.REVERSE
5.DISPLAY
6.EXIT
Enter your choice: 1

Enter element: 55
MENU
1.INSERT ELEMENT
2.SEARCH
3.COPY
4.REVERSE
5.DISPLAY
6.EXIT
Enter your choice: 5

CONTENTS OF LINKED LIST
55      44      33      22      11
MENU
1.INSERT ELEMENT
2.SEARCH
3.COPY
4.REVERSE
5.DISPLAY
6.EXIT
Enter your choice: 2

Enter element: 44

Successfull search....
MENU
1.INSERT ELEMENT
2.SEARCH
3.COPY
4.REVERSE
5.DISPLAY
6.EXIT
Enter your choice: 2

Enter element: 66

Unsuccessful search....
MENU
1.INSERT ELEMENT
2.SEARCH
3.COPY
4.REVERSE
5.DISPLAY
6.EXIT
Enter your choice: 3

LINKED LIST COPIED....
MENU
1.INSERT ELEMENT
2.SEARCH
3.COPY
4.REVERSE
5.DISPLAY
6.EXIT
Enter your choice: 5

CONTENTS OF LINKED LIST
55      44      33      22      11
MENU
1.INSERT ELEMENT
2.SEARCH
3.COPY
4.REVERSE
5.DISPLAY
6.EXIT
Enter your choice: 4

LINKED LIST REVERSED....
MENU
1.INSERT ELEMENT
2.SEARCH
3.COPY
4.REVERSE
5.DISPLAY
6.EXIT
Enter your choice: 5

CONTENTS OF LINKED LIST
55      44      33      22      11
MENU
1.INSERT ELEMENT
2.SEARCH
3.COPY
4.REVERSE
5.DISPLAY
6.EXIT
Enter your choice: 6
************************************************************************************************/



Program#1  

/* Write a program to implement circular linked list with its operation */

#include<stdio.h>
#include<conio.h>
typedef struct node
{
int info;
struct node *link;
}NODE;
void cinsert(NODE*,int);
void cdelfirst(NODE*);
void display(NODE*);
void main()
{
int ch,a;
NODE *HEAD;
clrscr();
HEAD=(NODE*)malloc(sizeof(NODE));
HEAD->link=HEAD;
while(1)
{
printf("\n\tMENU\n1.INSERT ELEMENT\n2.DELETE ELEMENT\n3.DISPLAY\n4.EXIT");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter element: ");
scanf("%d",&a);
cinsert(HEAD,a);
break;
case 2:
cdelfirst(HEAD);
break;
case 3:
display(HEAD);
break;
case 4:
exit(0);
}
}
}
void cinsert(NODE *HEAD,int x)
{
NODE *NEW;
NEW=(NODE*)malloc(sizeof(NODE));
NEW->info=x;
NEW->link=HEAD->link;
HEAD->link=NEW;
return;
}
void cdelfirst(NODE *HEAD)
{
NODE *OLD;
if(HEAD->link==HEAD)
{
printf("\nLINKED LIST UNDERFLOW....!!");
return;
}
OLD=HEAD->link;
HEAD->link=OLD->link;
printf("\nElement deleted= %d",OLD->info);
return;
}
void display(NODE *HEAD)
{
NODE *SAVE;
printf("\nCONTENTS OF LINKED LIST\n");
SAVE=HEAD->link;
while(SAVE!=HEAD)
{
printf("%d\t",SAVE->info);
SAVE=SAVE->link;
}
}
/*****************************************OUTPUT**********************************************
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 11

MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 22

MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 33

MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 44

MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 55

MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 3

CONTENTS OF LINKED LIST
55      44      33      22      11
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 55
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 44
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 33
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 22
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 11
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 2

LINKED LIST UNDERFLOW....!!
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 4
*************************************************************************************************/




























Program#2  

/* Write a program to implement doubly linked list with its operation */

#include<stdio.h>
#include<conio.h>
typedef struct node
{
int info;
struct node *lptr,*rptr;
}NODE;
NODE* doubinsfirst(NODE*,int);
NODE* doubdelfirst(NODE*);
void display(NODE*,NODE*);
void main()
{
NODE *L,*R;
int ch,x;
clrscr();
L=R=NULL;
while(1)
{
printf("\n\tMENU\n1.INSERT ELEMENT\n2.DELETE ELEMENT\n3.DISPLAY\n4.EXIT");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter element: ");
scanf("%d",&x);
if(L==NULL)
L=R=doubinsfirst(L,x);
else
L=doubinsfirst(L,x);
break;
case 2:
if(L==R)
L=R=doubdelfirst(L);
else
L=doubdelfirst(L);
break;
case 3:
display(L,R);
break;
case 4:
exit(0);
}
}
}
NODE* doubinsfirst(NODE *L,int x)
{
NODE *NEW;
NEW=(NODE*)malloc(sizeof(NODE));
NEW->info=x;
NEW->lptr=NULL;
if(L==NULL)
{
NEW->rptr=NULL;
return(NEW);
}
else
{
NEW->rptr=L;
L->lptr=NEW;
return(NEW);
}
}
NODE* doubdelfirst(NODE *L)
{
if(L==NULL)
{
printf("\nDOUBLY LINKED LIST UNDERFLOW....!!");
return(L);
}
if(L==L->rptr)
return(NULL);
printf("\nElement deleted= %d",L->info);
L=L->rptr;
L->lptr=NULL;
return(L);
}
void display(NODE *L,NODE *R)
{
NODE *SAVE;
int ch;
if(L==NULL)
{
printf("\nDOUBLY LINKED LIST EMPTY....!!");
return;
}
printf("\n\tSUB MENU\n1.LEFT TO RIGHT\n2.RIGHT TO LEFT");
printf("\nEnter your choice: ");
scanf("%d",&ch);
printf("\nCONTENTS OF LINKED LIST\n");
switch(ch)
{
case 1:
SAVE=L;
while(SAVE!=NULL)
{
printf("%d\t",SAVE->info);
SAVE=SAVE->rptr;
}
break;
case 2:
SAVE=R;
while(SAVE!=NULL)
{
printf("%d\t",SAVE->info);
SAVE=SAVE->lptr;
}
break;
}
}
/*****************************************OUTPUT**********************************************
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 10

MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 20

MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 30

MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 40

MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 1

Enter element: 50

MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 3

SUB MENU
1.LEFT TO RIGHT
2.RIGHT TO LEFT
Enter your choice: 1

CONTENTS OF LINKED LIST
50     40      30      20      10
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 3

SUB MENU
1.LEFT TO RIGHT
2.RIGHT TO LEFT
Enter your choice: 2

CONTENTS OF LINKED LIST
10      20 30      40      50
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 10
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 20
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 30
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 40
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 2

Element deleted= 50
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 2

DOUBLY LINKED LIST UNDERFLOW....!!
MENU
1.INSERT ELEMENT
2.DELETE ELEMENT
3.DISPLAY
4.EXIT
Enter your choice: 4
***********************************************************************************************/





No comments

Theme images by enjoynz. Powered by Blogger.