-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedListQueue.java
68 lines (56 loc) · 1.09 KB
/
linkedListQueue.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
66
67
68
import java.util.*;
public class linkedListQueue {
private LinkedList<Integer> queue = new LinkedList<Integer>();
private int queueRear;
public linkedListQueue(int x, int y) {
queue.add(x);
queue.add(y);
queueRear = 1;
}
public linkedListQueue(int x) {
queue.add(x);
}
public boolean addQueue(int n) {
queueRear++;
if(queueRear >= queue.size()) {
queue.addLast(n);
queueRear = 0;
}
else {
queue.addLast(n);
}
return true;
}
public boolean deleteQueue() {
if(!this.isEmptyQueue()){
queue.removeFirst();
return true;
} else {
System.out.println("This queue is empty.");
return false;
}
}
public int size() {
return queue.size();
}
public boolean isEmptyQueue() {
return queue.size() == 0;
}
public int front() {
return queue.getFirst();
}
public int back() {
return queue.getLast();
}
public String toString() {
String yes = "[";
for(int i = 0; i < queue.size() - 2; i++) {
yes += queue.get(i) + ", ";
}
yes += queue.get(queue.size() - 1) + "]";
return yes;
}
public int get(int n){
return queue.get(n);
}
}