-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDequeue.java
More file actions
78 lines (71 loc) · 1.5 KB
/
Dequeue.java
File metadata and controls
78 lines (71 loc) · 1.5 KB
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
public class Dequeue
{
int arr[]= new int[50];
int l,front,rear;
Dequeue(int L)
{
l=L;
front=rear=0;
}
void addrear(int n)
{
if(rear==l)
System.out.println("OVERFLOW FROM REAR");
else
{
if(rear==-1)
rear=0;
arr[rear]=n;
rear++;
}
}
void addfront(int n)
{
if(rear!=-1 && front > 0 && front <= rear)
{
front--;
arr[front]=n;
}
else
System.out.println("OVERFLOW FROM FRONT");
}
int popfront()
{
if(rear==-1 || front>rear|| arr[front]==0)
{
System.out.println("UNDERFLOW FROM FRONT");
return(-9999);
}
else
{
int temp=arr[front];
front++;
return temp;
}
}
int poprear()
{
if (rear==-1 || front==-1 || front>rear)
{
System.out.println("UNDERFLOW FROM REAR");
return(-9999);
}
else
{
rear--;
int temp=arr[rear];
return temp;
}
}
void display()
{
if(rear==-1 || front>=rear)
System.out.println("UNDERFLOW DEQUEUE");
else
{
System.out.println("THE ELEMENTS in the DEQUEUE are:-");
for(int i=front ;i<rear;i++)
System.out.println(arr[i]+"\t");
}
}
}