Professional Documents
Culture Documents
Ds File Extended
Ds File Extended
#include<stdio.h>
#define max 3
int q[l0l,front-0,rcor=-l:
void main()
int ch;
void insert():
void delet();
void display();
clrscr();
printf("\nCircular Queue operations\n");
printf("1.insert\n2.delete\n3.display\n4.exit\n");
wh.ilw (1)
printf("Enter your
choice:"); scanf("%d",&ch);
switch (ch)
case 1: insert();
reolme
break;
case 2: delet(),
break:
case 3:display();
break;
case 4:exit();
default:printf("Invalid option\n");
void insert()
int x;
i f((front==OGGrCar - x-1)||(front>0&Grcar’-front-1))
rear—0; qtrcarl
—x;
l
‹l'-•
if((front=—0&&rear==-1)| l (rear!=front-1))
q[++rear]=x;
void delet()
int a;
i-((front==0)&&(rear==-1))
printf("Queue is underflow\n")
getch();
exit();
if(front==rear)
a=q[front);
rear=-1;
front=0;
. (front==max-1)
a=q(front)}
front 0.
void dlsplay()
i1 t i,j;
(front==0s rear==-l)
piintf(”Queue is underflow\
n"); getch():
exit():
if(front>rear)
for(i=0;i<=rear,i++)
printf("\t%d",qli));
for(j=front;j<=max-l;j++)
printf("\t%d",q{j]);
printf("\nrear is at %d\
n",q[rear]), printf("\nfront is at
%d\n",q[front]);
for(i=front;i<=rear,i++)
printf("\t%d“,q[il);
printf("\nrear is at %d\n",qtrear]);
printf("\nfront is at %d\
n“,qlfront]);
getch(),
21. Write a program In C language to Implement the push operation In STACK using arrays
//include<stdlib.li>
#defit e size 3
Stl”\ict stack (
int s[size);
int stfull() (
if(st.top >= size - 1)
retuni 1;
else
return 0;
int stempty() {
if(st.top == -1)
return 1;
else
return 0;
ilJt pop()
( iilt item;
itcn = st.s[st.toyj;
st.top--;
void display() {
if(stciupty())
print("\nStaclt 1s Einptyl");
else (
for (i = st.top; i >= 0; i--)
priiitf{"\n%d", st.s[i]);
int iiiain() (
int item, choice;
char ans;
st.top = -I ;
printf("\n\tIinplementation Of Stack");
do (
printf("\nMain Menu");
printf("\n1.Push \n2.Pop \n3.Display \n4.exit");
r‹m N
printf("\nEnter Your Choice"); mel
scanf("%d", &choice);
switch (choice) {
case 1:
priiitf("\nStack is Full!");
' (st*"'l°*â’())
)3l‘il1l("\riEiupty stacl‹! Underflosv !!");
break;
case 3:
display();
break;
ease 4:
exit(0);
realme
return 0;
22. Wr1te a program in C language to implement the pop operation in STACK USi0g 8Y Fa 'Y 5
dc fine size 5
struct stack (
} st;
int stfull() (
if(st.top >= size - 1)
return I ;
else
retuni 0;
st.top+-r ;
st.s[st.top] = item;
int steirpty()
{ if(st.top == -
l)
return 1;
else
return 0;
int pop() (
int item;
item' st.s[st.t°p]
i lit i:
int main() I
int item, choice;
char airs;
st.top = - I ;
pi intf("\n\tImplernentation Of Stack");
do (
printf("\nMain Menu");
printf(”\n1.Push \n2.Pop \n3.Display \n4.exit”);
printf("\nEnter Your Choice");
scanf("%d", &clioice);
switch (choice) { realme
case I:
printf("\nEnter The item to be pushed");
scaiif("%d", &itein);
if(stfull())
printf("\nStack is Filll!");
if(stent Jity())
prilitf( \uLiiiJity stnck1 Un derfiosv 11");
break;
case 3:
display();
bicak;
case 4:
exit(0);
return 0;
fl4.Writ e a program in C language to implemen t the pop operation in STACK using
node *top;
int data, iterri, choice;
char ans, ch;
clrscr();
top = NULL;
switch (choise) (
case l:
printf("\nEnter the data");
scalif("%d", &data);
Push(data, &top);
break;
case 2:
if(Sein pty(top))
printf("\nStack underfiow!");
else (
item = Pop(&top);
printf(”\nTlie popped node is%d", item);
break;
case 3:
Display(&top);
bi cnk;
cosc 4:
Jii’intf("\iiDo You ivoiil T’o Quil?(y/n)")'
cli = gctclic();
if(cli == 'y’)
exit(0);
1 nC}mde<stdio.h>
int main()
int option;
printf(">>> c program to implement queue operations <<<"),
de
printf("\n\n 1.Insert an
element"); printf("\n 2.Delete an
element”); printf("\n 3.Display
queue"); printf{"\n 4.Exit");
printf("\n Enter your choice: ");
scanf("%d",&option);
-:‹itc:h(option)
casc 1: insert_element();
break;
case. 2: delete_eIement();
break;
case 3: display_queue();
break;
e 4: retuir 0;
)*Mni 1' (option!-4):
Void insert_elemeut()
int num;
plintf("\n Enter the number to inourtcd: "):
bc
s can I ( " ?, ” , r nun) .-
f(front---0 && rear—-MAX-1)
plintf("\n Queue Overflow Occurod”);
1.' (front= =- l &&rear =--1)
front=rear=0;
reo r= 0 ;
queue { rear =num i
rear++;
queue re ar —num i
oid delete_element()
int element;
if(front==-1)
printf("\n Underflow");
element=queue frontJ ;
if(front==rear)
front=rear=-1;
if(front==MAX-1)
front=0:
else
front++;
printf("\n The deleted element is: %d",element);
display_queue()
int i;
f(front-=-1)
printf("\n loo elements to display”);
void
Insert(int); int
Delete(); void
Display();
NODE *front, *rear; /* Global Declarations */
main() {
/* Main Program
*/ int opn, elem;
front - rear =
NULL; do {
clrscr();
printf("\n ### Linked List Implementation of QUEUE Operations #„
\n\n");
printf("\n Press 1-Insert, 2-Delete, 3-Display,4-Exit\n"):
printf("\n Your option ? “);
scanf("%d", &opn);
switch (opn)
{ case 1:
printf("\n\nRead the Element to be Inserted ?");
scanf("%d",
&elem);
Insert(elem);
break;
case 2:
elem = Delete();
lii;tf(”Linked List Implementation of Queue: Otatun:\n") :
Display();
Lleak;
case 4:
printf("\n\n Terminating \n\n");
Lreak;
default:
printf("\n\nInvalid Option !!! Try Again !! \n\n”);
break;
int Delete()
{ int info;
NODE *t;
if (front == NULL)
( printf(" Underflow! !
!"); return -l;
} else {
t front;
info = front->data;
if (front == rear)
rear = NULL;
front = front->link;
t->link = NULL;
free(t);
return (info);
void Display()
( NODE *t;
if (front == NULL)
printf("Empty Queue\n");
else {
t front;
printf("Front->");
while lt) (
printf("[%d)->", t->data);
t - t->link;
printf("Rear\n");
reolme
27. Write a program in C language to implement the circular queue.
r -1;
} /* Q has only one element ? */
else
f = (f + 1) % SIZE;
return (elem);