-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueLL.java
More file actions
73 lines (65 loc) · 1.23 KB
/
QueueLL.java
File metadata and controls
73 lines (65 loc) · 1.23 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
65
66
67
68
69
70
71
72
73
/**
* This is class to modify the queue data
*
* @author Ching2 Huang
*
* @param <T> take in any type
*/
public class QueueLL<T> implements Queue<T> {
//the list to store the stack
private LinkedList<T> list = new LinkedList<T>();;
/**
* Tests if the queue is empty.
*
* @return true iff the queue is empty
**/
@Override
public boolean isEmpty() {
return list.isEmpty();
}
/**
* Gets the element at the front of the queue without removing it.
*
* @return the peeked data
**/
@Override
public T peek() {
return list.getLast();
}
/**
* Removes the front element of the queue and returns it.
*
* @return the dequeued data
**/
@Override
public T dequeue() {
// get the data of the queue
T data = list.getLast();
// delete the data
list.deleteLast();
// return the deleted data
return data;
}
/**
* Adds an element to the end of the queue.
**/
@Override
public void enqueue(T data) {
list.insertFirst(data);
}
/**
* Returns a String representation of the queue.
*
* @return stack as String
*/
public String toString(){
return list.toString();
}
/**
* get the number of orders
* @return the size of orders
*/
public int getSize(){
return list.size();
}
}