forked from bishweashwarsukla/hactoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDEQUEUE.cpp
121 lines (119 loc) · 1.66 KB
/
DEQUEUE.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include<stdio.h>
#include<conio.h>
struct item
{
int data;
struct dequeueitem *next;
};
struct dequeue
{
struct dequeueitem *front;
int size;
struct dequeueitem *rear;
};
void dequeue(struct dequeue *dq)
{
dq->front= null;
dq->size= 0;
dq->rear= null;
}
void addfront(Struct dequeue *dq, int x)
{
struct dequeue *ptr;
ptr=(struct dequeueitem*)malloc(sizeof(dequeueitem));
ptr->item=x;
if(Empty(dq))
{
dq->front = ptr;
dq->rear =ptr;
dq->size= 1;
return;
}
ptr->next = dq->front;
dq->front = ptr;
(dq->size)++;
}
int empty(struct dequeue *dq)
{
if(dq->size==0);
return;
else
return 0;
}
void addrear (struct dequeue *dq, int x)
{
struct dequeue *ptr;
ptr=(struct dequeueitem*)malloc(sizeof(dequeueitem));
ptr->item=x;
if(Empty(dq))
{
dq->front = ptr;
dq->rear =ptr;
dq->size= 1;
return;
}
ptr->next = dq->front;
dq->front = ptr;
(dq->size)++;
}
int size(struct dequeue *dq )
{
return(dq->size);
}
int deletefront (struct dequeue *dq)
{
int x;
struct dequeueitem *ptr;
if(Empty (dq))
}
printf("UNDERFLOW");
return;
}
x=dq->front->item;
dq->front=null;
tree(dq->rear);
dq->rear=null;
dq->size=0;
return x;
}
else
{
x=dq->front->item
ptr=dq->front;
dq->front=ptr->next;
tree(ptr);
(dq->size);
return x;
}
}
int deleterear(struct dequeue *dq)
{
int x;
struct dequeueitem *ptr;
if(Empty (dq))
}
printf("UNDERFLOW");
return;
}
if(size(dq)==1)
{
x=dq->front->item;
dq->front=null;
tree(dq->rear);
dq->rear=null;
dq->size=0;
}
return x;
else
{
ptr=dq->front;
while(ptr->next!=dq->rear)
ptr=ptr->next;
x=ptr->next->item;
tree(dq->rear);
ptr->next=null;
dq->rear=ptr;
(dq->size);
return x;
}
}