-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.java
More file actions
50 lines (41 loc) · 1.29 KB
/
Queue.java
File metadata and controls
50 lines (41 loc) · 1.29 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
import java.util.*;
//the Queue class with a LinkedList field
public class Queue
{
protected LinkedList list;
//queue object has been initialized
public Queue()
{
list = new LinkedList();
} //default constructor
//check whether queue object has no elemet or otherwise
public boolean isEmpty()
{
return list.isEmpty();
}//method isEmpty
//determine the no of elements in the queue object
public int size()
{
return list.size();
}// method size
//insert element at the back of the queue object
public void enqueue(Object element)
{
list.addLast(element);
} //method enqueue
//remove the front element from the queue object
public Object dequeue()
{
return list.removeFirst();
} //method dequeue
//the element at the front of the queue object has been returned
public Object front()
{
return list.getFirst();
} //method front
//the element at the end of the queue object has been returned
public Object rear()
{
return list.getLast();
} //method rear
} // Queue class