-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoubleQueue.java
More file actions
44 lines (37 loc) · 837 Bytes
/
DoubleQueue.java
File metadata and controls
44 lines (37 loc) · 837 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 class01;
/**
* @author pacai
* @version 1.0
*/
public class DoubleQueue<T> {
Node head;
Node tail;
class Node {
T data;
Node next;
Node last;
public Node(T data) {
this.data = data;
}
}
public void addFromHead(Node head, T data) {
Node node = new Node(data);
if (head == null){
head = tail = node;
}else{
node.next = head;
head.last = node;
head = node;
}
}
public void addFromTail(Node tail, T data) {
Node node = new Node(data);
if(tail == null){
head = tail = node;
}else{
tail.next = node;
node.last = tail;
tail = node;
}
}
}