-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdouble ended queue right.cpp
79 lines (75 loc) · 1 KB
/
double ended queue right.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
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#define size 5
struct doubly
{
int dq[size];
int left=-1,right=-1;
};
void insert_right(struct doubly *s)
{
int item;
if(s->left==0&&s->right==size||s->left==s->right+1)
{
printf("overflow\n");
exit(2);
}
else if(s->right==-1)
{
s->left=s->right=0;
}
else if(s->right==size-1)
{
s->right=0;
}
else
{
s->right++;
}
printf("enter item\n");
scanf("%d",&item);
s->dq[s->right]=item;
}
void delete_right(struct doubly *s)
{
if(s->right==-1)
{
printf("underflow\n");
exit(3);
}
else if(s->left==s->right)
{
s->left=s->right=-1;
}
else if(s->right==0)
{
s->right==size-1;
}
else
{
s->right--;
}
}
int main()
{
doubly l;
int choice;
do
{
printf("press 1 to insert\npress 2 to delete\npress 3 to exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1: insert_right(&l);
break;
case 2: delete_right(&l);
break;
case 3:exit(5);
default:
printf("invalid\n");
}
}while(choice!=3);
getch();
return 0;
}