11package dataStructures .queue ;
22
3- import java . util . Deque ;
3+
44import java .util .ArrayDeque ;
5+ import java .util .Deque ;
56
67/**
7- * Implementation of a non-increasing (decreasing) monotonic queue for certain (but common) use case:
8- * When larger objects pushed to the queue are able to replace and represent smaller objects that come before it.
9- * Callable methods are:
10- * isEmpty()
11- * max()
12- * pop()
13- * push()
14- * @param <T> generic type for objects to be stored or queried
15- *
16- * index v Increasing queue Decreasing queue
17- * 1 5 [5] [5]
18- * 2 3 [3] 3 kick out 5 [5, 3] #3->5
19- * 3 1 [1] 1 kick out 3 [5, 3, 1] #1->3
20- * 4 2 [1, 2] #2->1 [5, 3, 2] 2 kick out 1 #2->3
21- * 5 4 [1, 2, 4] #4->2 [5,4] 4 kick out 2, 3 #4->2
22- */
8+ * Implementation of a non-increasing (decreasing) monotonic queue
9+ * for certain (but common) use case:
10+ * When larger objects pushed to the queue are able to replace and represent
11+ * smaller objects that come before it.
12+ * Callable methods are:
13+ * isEmpty()
14+ * max()
15+ * pop()
16+ * push()
17+ * <p></p>
18+ * Movement within the monotonic-queue:
19+ * index v Increasing queue Decreasing queue
20+ * 1 5 [5] [5]
21+ * 2 3 [3] 3 kick out 5 [5, 3] #3->5
22+ * 3 1 [1] 1 kick out 3 [5, 3, 1] #1->3
23+ * 4 2 [1, 2] #2->1 [5, 3, 2] 2 kick out 1 #2->3
24+ * 5 4 [1, 2, 4] #4->2 [5,4] 4 kick out 2, 3 #4->2
25+ *
26+ * @param <T> generic type for objects to be stored or queried
27+ */
2328
2429public class MonotonicQueue <T extends Comparable <T >> {
2530 private Deque <T > dq = new ArrayDeque <>(); // or LinkedList
2631
2732 /**
2833 * Checks if queue is empty.
34+ *
2935 * @return boolean
3036 */
3137 public boolean isEmpty () {
@@ -34,7 +40,8 @@ public boolean isEmpty() {
3440
3541 /**
3642 * Push an object into the queue and maintain the non-increasing property.
37- * @param obj to be inserted
43+ *
44+ * @param obj to be inserted.
3845 */
3946 public void push (T obj ) {
4047 Integer count = 0 ;
@@ -46,6 +53,7 @@ public void push(T obj) {
4653
4754 /**
4855 * Returns the highest value stored in the queue.
56+ *
4957 * @return the first value of the queue.
5058 */
5159 public T max () {
@@ -58,6 +66,8 @@ public T max() {
5866 /**
5967 * Returns the highest valued object in the queue; i.e the first object;
6068 * Removal will only be done all representation of the object has been accounted for.
69+ *
70+ * @return The first value in the deque. (Highest valued object)
6171 */
6272 public T pop () {
6373 if (dq .isEmpty ()) {
0 commit comments