-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.java
More file actions
51 lines (45 loc) · 745 Bytes
/
Copy pathQueue.java
File metadata and controls
51 lines (45 loc) · 745 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
public class Queue<T> {
private T data;
SinglyLinkedList<T> first;
SinglyLinkedList<T> last;
public void enqueue(T data)
{
SinglyLinkedList<T> newNode=new SinglyLinkedList<T>(data);
if(first==null)
first=last=newNode;
else
{
last.setNextNode(newNode);
last=newNode;
}
}
public T dequeue()
{
if (first==null)
{
last=null;
return null;
}
else{
SinglyLinkedList<T> returnValue=first;
first=first.getNextNode();
returnValue.setNextNode(null);
return returnValue.getData();
}
}
public void display()
{
SinglyLinkedList<T> currentNode=first;
while(currentNode!=null)
{
System.out.println(currentNode.getData());
currentNode=currentNode.getNextNode();
}
}
public boolean isEmpty()
{
if (first==null)
return true;
return false;
}
}