-
Notifications
You must be signed in to change notification settings - Fork 6
/
DeQ.c
executable file
·79 lines (79 loc) · 1.38 KB
/
DeQ.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
#include<stdio.h>
int front = -1;
int rear = -1;
int a[10];
void rearpush (int item)
{
if(rear == -1)
{
front = 0;
rear = 0;
a[rear++]=item;
}
else if (rear == 9)
{
printf("Cannot Insert\n");
}
else
{
a[rear++]=item;
}
}
void rearpop ()
{
if(rear == -1)
{
printf("Cannot delete\n");
}
else if (rear>0)
{
printf("The element which is being deleted is, %d\n",a[--rear]);
}
}
void frontpop ()
{
if(front == -1)
{
printf("Cannot Delete\n");
}
else if (front == rear)
{
printf("Cannot Delete\n");
}
else
{
printf("The element which is being deleted is, %d\n",a[++front]);
}
}
void frontpush(int item)
{
if(front == -1)
{
printf("Cannot insert\n");
}
else if (front >0)
{
a[front--]=item;
}
}
void display ()
{
for(int i = front;i<rear;i++)
printf("%d\n",a[i]);
}
int main ()
{
printf("You have three choices : 1. FrontPush () 2. FrontPop () 3. Dislpay () 4. RearPush () 5. RearPop ()");
int num;
do
{
printf("\nEnter your choice : ");
scanf("%d",&num);
if(num==1){int item;printf("Enter the number you want to push in : ");scanf("%d",&item);frontpush(item);}
if(num==2){frontpop();}
if(num==3){display();}
if(num==4){int item;printf("Enter the number you want to push in : ");scanf("%d",&item);rearpush(item);}
if(num==5){rearpop();}
}while (num!=6);
return 0;
}