forked from shreyajainn/Data-structures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deque.cpp
93 lines (88 loc) · 1.14 KB
/
deque.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
93
using namespace std;
#include<iostream>
int left1=-1;
int right1=-1;
int arr[90]={0};
int size=7;
void right_insertion(int p)
{
if((left1==-1 )&&(right1==-1))
{
left1=left1+1;
right1=right1+1;
arr[right1]=p;
}
else if((right1==size-1)&&left1==0)
{
cout<<"overflow"<<endl;
}
else if((right1==size-1)&&left1!=0)
{
right1=0;
arr[right1]=p;
}
else if(left1==right1+1)
{
cout<<"overflow"<<endl;
}
else
{
right1=right1+1;
arr[right1]=p;
}
}
int left_insertion(int k)
{
if(left1==-1&&right1==-1)
{
left1=left1+1;
right1=right1+1;
arr[left1]=k;
}
else if(right1==size-1&&left1==0)
{
cout<<"overflow"<<endl;
}
else if( right1!=size-1&&left1==0)
{
left1=size-1;
arr[left1]=k;
}
else if(right1==left1+1)
{
cout<<"overflow"<<endl;
}
else
{
left1=left1-1;
arr[left1]=k;
}
}
int left_deletion()
{
}
int right_deletion()
{
}
traverse()
{
left1=0;
{
while(left1!=size-1)
{
cout<<arr[left1]<<endl;
left1=left1+1;
}
}
cout<<arr[left1]<<endl;
}
int main()
{
left_insertion(23);
left_insertion(36);
left_insertion(21);
right_insertion(788);
right_insertion(123);
right_insertion(456);
traverse();
}