-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lqueue.java
56 lines (48 loc) · 1.09 KB
/
Lqueue.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
import components.LinkedList;
//first in first out
public class Lqueue<T extends Comparable<T>> implements XQueueInterface<T> {
LinkedList<T> qu = new LinkedList<>();
@Override
public void enqueue(T data) {
//add to the last, on the back Node to have constant time
qu.insertLast(data);
}
@Override
public T dequeue() {
//delete from head
if(!isEmpty()) {
T toPop = (T) qu.dummy.getNext().getData();
qu.delete(toPop);
return toPop ;
}
return null;//list is empty
}
@Override
public T getFront() {
//return the value on the head and update the head
if(!isEmpty()) {
T toPop = (T) qu.dummy.getNext().getData();
return toPop ;
}
return null;
}
@Override
public boolean isEmpty() {
//if head and back are null
if(qu.head== qu.dummy && qu.back==qu.dummy) {
return true;
}
return false;
}
@Override
public void clear() {
//adjust both back and head at null
qu.head= qu.dummy ;
qu.back=qu.dummy;
}
@Override
public T pop() {
// TODO Auto-generated method stub
return null;
}
}