-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.java
More file actions
53 lines (35 loc) · 998 Bytes
/
Queue.java
File metadata and controls
53 lines (35 loc) · 998 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
45
46
47
48
49
50
51
52
53
package com.employee;
// ************************************ TODO G1 ************************************
/*
* Implement a Queue and its basic operations using LinkedList
*/
public class Queue {
// ************************************ SOLUTION G1 BEGIN ************************************
static class QueueNode {
int id;
QueueNode next;
public QueueNode(int id) {
this.id = id;
}
}
QueueNode front;
QueueNode rear;
public void add(int id) {
if(front == null) {
front = new QueueNode(id);
rear = front;
return;
}
rear.next = new QueueNode(id);
rear = rear.next;
}
public void poll() {
if(front == null) {
return;
}
QueueNode temp = front;
front = front.next;
temp.next = null;
}
// ************************************ SOLUTION G1 END ************************************
}