-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDequeUtil.java
More file actions
100 lines (80 loc) · 1.14 KB
/
Copy pathDequeUtil.java
File metadata and controls
100 lines (80 loc) · 1.14 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package datastructures;
import java.util.Scanner;
import bridgelabz.utility.Deque;
public class DequeUtil<E>
{
static Scanner sc=new Scanner(System.in);
Deque<E>front;
Deque<E>Rear;
int size=0;
@SuppressWarnings("null")
public void addFront(E c)//to insert c in the begining
{
if(front==null) //if no elements in list
{
front.data=c;
Rear=front;
}
else
{
Deque<E>tNode=null;
tNode.data=c;
tNode.next=front;
tNode.prev=tNode;
front=tNode;
}
size++;
}
public void addRear(E c)
{
if(front==null)
{
Deque<E>tNode=new Deque<E>(c);
front=tNode;
Rear=tNode;
}
else
{
Deque<E>tNode=new Deque<E>(c);
Rear.next=tNode;
tNode.prev=Rear;
Rear=tNode;
}
size++;
}
public E removeFront()
{
E val=null;
if(front==null)
{
System.out.println("No elements to delete");
}
else
{
val=front.data;
front=front.next;
}
size++;
return val;
}
public E removeRear()
{
E val=null;
if(front==null)
{
System.out.println("No elements to delete");
}
else
{
val=Rear.data;
front=front.prev;
Rear.next=null;
}
size--;
return val;
}
public String getstring()
{
return sc.next();
}
}