-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.java
More file actions
64 lines (46 loc) · 1.17 KB
/
Queue.java
File metadata and controls
64 lines (46 loc) · 1.17 KB
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
package calculator;
public class Queue {
// fields
listNode front;
listNode rare;
// add the element to the rare
public void EnQueue(String data) {
// making a new node
listNode input = new listNode(data);
// when the queue is empty
if(front == null && rare == null) {
// front and rare point both towards input node
front = input;
rare = input;
}
// when the queue is not empty
else {
// link the input node to the previous rare
rare.next = input;
// point rare to input
rare = input;
}
}
// retrieve the data from the front
public String DeQueue() {
// a string variable to hold the returned value
String returnedValue;
// when there is only one node in the queue
if(front == rare) {
// store the value that need to be returned
returnedValue = front.data;
// set the front and rare to be null
front = null;
rare = null;
return returnedValue;
}
// when the queue currently has more than one listNode
else {
// get the returned value
returnedValue = front.data;
// point the front to the next element
front = front.next;
return returnedValue;
}
}
}