-
Notifications
You must be signed in to change notification settings - Fork 581
Expand file tree
/
Copy pathmyDeque.java
More file actions
44 lines (37 loc) · 749 Bytes
/
myDeque.java
File metadata and controls
44 lines (37 loc) · 749 Bytes
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
package Ds.Queue;
public class myDeque<E> {
Node head , tail;
public void addHead(E data) {
Node <E> toAdd = new Node(data);
if(head==null) {
head = tail = toAdd;
return;
}
head.next = toAdd;
toAdd.previous = head;
toAdd= head;
}
public E removeLast() {
if(head==null) {
return null;
}
Node<E> toRemove = tail;
tail = tail.next;
tail.previous = null;
if(tail == null) {
head = null;
}
return toRemove.data;
}
public static class Node<E>{
E data;
Node next , previous;
public Node(E data) {
this.data = data;
this.next = this.previous = null;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}