This repository was archived by the owner on Mar 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.java
More file actions
98 lines (85 loc) · 2.35 KB
/
Copy pathQueue.java
File metadata and controls
98 lines (85 loc) · 2.35 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* This is a simplified interface for Queue, based on the Java API.
* See <a href="https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/Queue.html">this documentation</a>
* for more details.
* @author Stephen J. Sarma-Weierman
* @author Hunter M. Shaw
* @version 1.0
*/
public interface Queue<T> {
/**
* See the documentation linked above for more details. Instead of throwing an exception
* if the maximum capacity is exceeded, we'll return false (if there is a capacity restriction).
* @param obj - object to be added.
* @return true if successful.
*/
public boolean add(T obj);
/**
* Adds specified element to queue.
* @return add(T obj) if successful.
* @return false if unsuccessful.
*/
public boolean offer(T obj);
/**
* Gets and removes front of queue.
* @return (T)Object o.
*/
public T remove();
/**
* Get and remove front of queue.
* @return remove() if successful.
* catch (NoSuchElementException ex).
* @return null.
*/
public T poll();
/**
* Method to get the front of the queue.
* @return (T)queue[front].
* Otherwise Throws NoSuchElementException.
*/
public T element();
/**
* @returns element() if successful
* @returns null if queue is empty
*/
public T peek();
/**
* Searches collection specified element. Returns true
only if Objects.equals(o, T)
* @param obj - element to search for within the collection.
* @return true if obj is found
* @return false if obj is not found
*/
public boolean contains(Object o);
/**
* @returns size.
*/
public int size();
/**
* Removes all emements from the collection.
* Resets queue[front] to zero.
* resets queue[back] to zero.
*/
public void clear();
/**
* Checks if collection is empty.
* @returns size == 0.
*/
public boolean isEmpty();
/**
* Returns an object array containing all elements within the collection.
* This method oes preserve the order of the circular queue.
* The methods returned array's runtime type is Object.
* @return arr
*/
public Object [] toArray();
/**
* Returns array contining all emements within the collection.
* The runtime type of returned array is that of the specified array.
* If collection fits within specified array returned that array.
* Otherwise, a new array is allocated.
* Returns array of type T.
* @return arr
*/
public T[] toArray(T[] a);
}