-
Notifications
You must be signed in to change notification settings - Fork 174
/
Copy pathdeque.c
109 lines (101 loc) · 1.66 KB
/
deque.c
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include<stdio.h>
#include<stdlib.h>
#define MAX 20
int front=0,rear=0;
int queue[MAX];
void insertf(int);
void insertr(int);
void deletef();
void deleter();
void display();
void main()
{
int d,ch;
do
{
printf("Choose a function\n 1)Insert at front\n 2)Insert at rear\n 3)Delete at front\n 4)Delete at rear\n 5)Display\n 6)Exit\n");
scanf("%d",&ch);
switch (ch)
{
case 1:
printf("Enter value:");
scanf("%d",&d);
insertf(d);
break;
case 2:
printf("Enter value:");
scanf("%d",&d);
insertr(d);
break;
case 3:
deletef();
break;
case 4:
deleter();
break;
case 5:
display();
break;
case 6:
exit(1);
default:
printf("Invalid Operation\n\n");
break;
}
}
while (1==1);
}
void insertf(int d)
{
int i;
if(rear==MAX)
printf("Queue is full\n");
else
{
for(i=MAX;i>=1;i--)
queue[i]=queue[i-1];
queue[0]=d;
rear++;
}
}
void insertr(int d)
{
if(rear==MAX)
printf("Queue is full\n");
else
{
queue[rear]=d;
rear++;
}
}
void deletef()
{
int d;
if(front==rear)
printf("Queue is empty\n");
else
{
d=queue[front];
printf("%d data deleted\n",d);
front++;
}
}
void deleter()
{
int d;
if(front==rear)
printf("Queue is empty\n");
else
{
rear--;
d=queue[rear];
printf("%d data deleted\n",d);
}
}
void display()
{
int i;
printf("Queue:\n");
for(i=front;i<rear;i++)
printf("%d\n",queue[i]);
}