-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListQueue.java
65 lines (49 loc) · 1.07 KB
/
ListQueue.java
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
/**
* COM212 Data Structure
* DQueue implementation with List
*
* by S. James Lee
*/
public class ListDQueue<E> {
private DLinkedList<E> aList;
public ListDQueue() {
aList = new DLinkedList<E>();
}
public int size() { return aList.size(); }
public boolean isEmpty() { return aList.isEmpty();}
public void addFirst(E e) {
aList.addFirst(e);
}
public void addLast(E e) {
aList.addLast(e);
}
public E removeFirst() {
return aList.removeFirst();
}
public E removeLast() {
return aList.removeLast();
}
public E getFirst() {
return aList.first();
}
public void remove(E e){
aList.remove(aList.get());
}
public E getLast() {
return aList.last();
}
public String toString() {
return aList.toString();
}
public static void main(String[] args) {
ArrayDQueue<String> myDQueue = new ArrayDQueue<String>();
myDQueue.addFirst("James");
myDQueue.addFirst("S.");
myDQueue.addLast("Lee");
System.out.println(myDQueue);
myDQueue.removeFirst();
System.out.println(myDQueue);
myDQueue.removeLast();
System.out.println(myDQueue);
}
}