-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedQueueOfStrings.java
More file actions
44 lines (39 loc) · 999 Bytes
/
Copy pathLinkedQueueOfStrings.java
File metadata and controls
44 lines (39 loc) · 999 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
/* *****************************************************************************
* Name: Rafael Neves Moraes
*
* Description: Queue algorithm object implementation.
*
* Written: 5/06/2019
*
* % javac LinkedQueueOfStrings.java
* % java LinkedQueueOfStrings
*
**************************************************************************** */
public class LinkedQueueOfStrings
{
private Node first, last;
private class Node
{
/* same as in StackOfStrings */
}
public boolean isEmpty()
{
return first == null;
}
public void enqueue(String item)
{
Node oldlast = last;
last = new Node();
last.item = item;
last.next = null;
if (isEmpty()) first = last;
else oldlast.next = last;
}
public String dequeue()
{
String item = first.item;
first = first.next;
if (isEmpty()) last = null;
return item;
}
}