-
Notifications
You must be signed in to change notification settings - Fork 10
/
QUEUE.CPP
92 lines (90 loc) · 2.24 KB
/
QUEUE.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include<stdio.h>
#include<conio.h>
void push(int stack[],int size,int &front,int &rear)
{ int element;
printf("element to be pushed =\n");
scanf("%d",&element);
if(rear==size-1)
printf("queue overflow");
else
{ if(rear==-1)
front=0;
stack[++rear]=element;
}
}
void pop(int stack[],int &front,int &rear)
{ if(front==-1)
printf("queue underflow");
else
{ if(front==rear)
{ printf("%d",stack[front]);
front=-1;rear=-1;
}
else
printf("poped element =%d",stack[front++]);
}
}
void display(int stack[],int &front,int &rear)
{
for(int i=front;i<=rear;i++)
printf("%d ",stack[i]);
}
void queue()
{ clrscr();
int element,b,stack[5],size=5,front=-1,rear=-1;
do{ printf("\n--------MENU--------\n");
printf("1.PUSH ELEMENT IN QUEUE\n");
printf("2.POP ELEMENT FROM QUEUE\n");
printf("3.DISPLAY ELEMENTS IN QUEUE\n");
printf("4.QUIT\n");
printf("enter your choice = \n");scanf("%d ",&b);
switch(b)
{ case 1:push(stack,size,front,rear);break;
case 2:pop(stack,front,rear);break;
case 3:display(stack,front,rear);break;
case 4:break;
default :printf("wrong choice enter again\n");
}
}while(b!=4);
getch();
}
void circular_queue()
{ clrscr();
int element,b,stack[5],size=5,front=-1,rear=-1;
do{ printf("\n--------MENU--------\n");
printf("1.PUSH ELEMENT IN QUEUE\n");
printf("2.POP ELEMENT FROM QUEUE\n");
printf("3.DISPLAY ELEMENTS IN QUEUE\n");
printf("4.QUIT\n");
printf("enter your choice = \n");scanf("%d ",&b);
switch(b)
{ case 1:push(stack,size,front,rear);break;
case 2:pop(stack,front,rear);break;
case 3:display(stack,front,rear);break;
case 4:break;
default :printf("wrong choice enter again\n");
}
}while(b!=4);
getch();
}
void main()
{
clrscr();
int a;
do{ clrscr();
printf("\n--------MENU--------\n");
printf("1.PERFORM NORMAL QUEUE\n");
printf("2.PERFORM CIRCULAR QUEUE\n");
printf("3.PERFORM DQUEUE\n");
printf("4.QUIT\n");
printf("enter your choice = ");scanf("%d",&a);
switch(a)
{ case 1:queue();break;
case 2:circular_queue();break;
case 3:break;
case 4:break;
default :printf("wrong choice enter again\n");
}
}while(a!=4);
getch();
}