-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathQueue.java
81 lines (71 loc) · 2.1 KB
/
Queue.java
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
74
75
76
77
78
79
80
81
package com.queues;
/**
* In computer science, a queue is a particular kind of abstract data type or
* collection in which the entities in the collection are kept in order and the
* principal (or only) operations on the collection are the addition of entities
* to the rear terminal position, known as enqueue, and removal of entities from
* the front terminal position, known as dequeue. This makes the queue a
* First-In-First-Out (FIFO) data structure. In a FIFO data structure, the first
* element added to the queue will be the first one to be removed.
*
* {@link https://en.wikipedia.org/wiki/Queue_(abstract_data_type)}
*
* @author STEPHANE MIGUEL KAKANAKOU (Skakanakou@gmail.com)
*
* @param <Item>
*/
public interface Queue<Item> extends Iterable<Item> {
/**
* Inserts the specified element at the end of this queue.
*
* @param item
* the element to add
*
* @exception java.lang.NullPointerException
* if item is null
*/
void add(Item item);
/**
* Retrieves and removes the head of this queue.
*
* @return the head of this queue
*
* @exception java.lang.IllegalStateException
* if the Queue is empty
*/
Item poll();
/**
* Retrieves but not removes the head of this queue.
*
* @return the head of this queue
*
* @exception java.lang.IllegalStateException
* if the Queue is empty
*/
Item peek();
/**
* Tests if this Queue is empty.
*
* @return true if the Queue empty and false if not.
*/
boolean isEmpty();
/**
* Removes all of the elements from this Queue.
*/
void clear();
/**
* Returns the number of elements in this Queue.
*
* @return size the number of elements in this Queue.
*/
int size();
/**
* Returns true if this Queue contains the specified element.
*
* @param item
* the item to look for.
*
* @return true if the Queue contains the item and false if not.
*/
boolean contains(Item item);
}