-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.java
More file actions
48 lines (42 loc) · 803 Bytes
/
Queue.java
File metadata and controls
48 lines (42 loc) · 803 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
package asg_2;
public class Queue {
sNode front;
sNode p;
public Queue( ){
front = null;
}
//Adds a node to the back of the queue
public void enqueue(Node n){
p = front;
if(p == null){
front = new sNode(n,front);
}else{
while(p.next!= null){
p = p.next;
}
p.next = new sNode(n, null);
}
}
//Removes a Node from the front of the Queue
public Node dequeue( ){
Node i;
if(front == null){
throw new NoItemException();
}
else {
i = front.item;
front=front.next;
return i;
}
}
//Checks if the queue is empty
public boolean empty(){
return front==null;
}
//Returns the Data from the front most node but does not dequeue
public Node peak(){
Node i;
i = front.item;
return i;
}
}