-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListNodeQueue.java
49 lines (35 loc) · 948 Bytes
/
ListNodeQueue.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
package week4.assignment5.reference;
import week4.assignment2.reference.ListNode;
public class ListNodeQueue {
private int size = 0;
private ListNode head = null; //삭제될 위치
private ListNode tail = null; //삽입될 위치
public ListNodeQueue(){
}
public void add(int data){
if(head == null){
head = new ListNode(data);
tail = head;
}else{
tail = tail.add(tail, new ListNode(data), 1);
}
size++;
}
public Integer peek(){
if(head == null) return null;
return head.getValue();
}
public Integer poll(){
if(head == null) return null;
ListNode prevHead = head.remove(head, 0);
head = prevHead.getNext();
size--;
return prevHead.getValue();
}
public boolean empty(){
return this.size == 0;
}
public int getSize(){
return size;
}
}