Skip to content

Commit 9b38ecd

Browse files
1 parent 4a83576 commit 9b38ecd

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

DataStructures/Queues/GenericArrayListQueue.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
/**
66
* This class implements a GenericArrayListQueue.
77
*
8-
* <p>A GenericArrayListQueue data structure functions the same as any specific-typed queue. The
9-
* GenericArrayListQueue holds elemets of types to-be-specified at runtime. The elements that are
10-
* added first are the first to be removed (FIFO) New elements are added to the back/rear of the
8+
* A GenericArrayListQueue data structure functions the same as any specific-typed queue. The
9+
* GenericArrayListQueue holds elements of types to-be-specified at runtime. The elements that are
10+
* added first are the first to be removed (FIFO). New elements are added to the back/rear of the
1111
* queue.
1212
*/
1313
public class GenericArrayListQueue<T> {
1414
/** The generic ArrayList for the queue T is the generic element */
15-
ArrayList<T> _queue = new ArrayList<T>();
15+
ArrayList<T> _queue = new ArrayList<>();
1616

1717
/**
18-
* Checks if the queue has elements (not empty)
18+
* Checks if the queue has elements (not empty).
1919
*
2020
* @return True if the queue has elements. False otherwise.
2121
*/
@@ -24,7 +24,7 @@ private boolean hasElements() {
2424
}
2525

2626
/**
27-
* Checks what's at the front of the queue
27+
* Checks what's at the front of the queue.
2828
*
2929
* @return If queue is not empty, element at the front of the queue. Otherwise, null
3030
*/
@@ -51,7 +51,7 @@ public boolean add(T element) {
5151
*
5252
* @return If queue is not empty, element retrieved. Otherwise, null
5353
*/
54-
public T poll() {
54+
public T pull() {
5555
T result = null;
5656
if (this.hasElements()) {
5757
result = _queue.remove(0);
@@ -65,19 +65,19 @@ public T poll() {
6565
* @param args Command line arguments
6666
*/
6767
public static void main(String[] args) {
68-
GenericArrayListQueue<Integer> queue = new GenericArrayListQueue<Integer>();
68+
GenericArrayListQueue<Integer> queue = new GenericArrayListQueue<>();
6969
System.out.println("Running...");
7070
assert queue.peek() == null;
71-
assert queue.poll() == null;
72-
assert queue.add(1) == true;
71+
assert queue.pull() == null;
72+
assert queue.add(1);
7373
assert queue.peek() == 1;
74-
assert queue.add(2) == true;
74+
assert queue.add(2);
7575
assert queue.peek() == 1;
76-
assert queue.poll() == 1;
76+
assert queue.pull() == 1;
7777
assert queue.peek() == 2;
78-
assert queue.poll() == 2;
78+
assert queue.pull() == 2;
7979
assert queue.peek() == null;
80-
assert queue.poll() == null;
80+
assert queue.pull() == null;
8181
System.out.println("Finished.");
8282
}
8383
}

DataStructures/Queues/LinkedQueue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public LinkedQueue() {
3838
/**
3939
* Check if queue is empty
4040
*
41-
* @return <tt>true</tt> if queue is empty, otherwise <tt>false</tt>
41+
* @return true if queue is empty, otherwise false
4242
*/
4343
public boolean isEmpty() {
4444
return size == 0;
@@ -48,7 +48,7 @@ public boolean isEmpty() {
4848
* Add element to rear of queue
4949
*
5050
* @param data insert value
51-
* @return <tt>true</tt> if add successfully
51+
* @return true if add successfully
5252
*/
5353
public boolean enqueue(int data) {
5454
Node newNode = new Node(data);

DataStructures/Queues/Queues.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* This implements Queues by using the class Queue.
55
*
6-
* <p>A queue data structure functions the same as a real world queue. The elements that are added
6+
* A queue data structure functions the same as a real world queue. The elements that are added
77
* first are the first to be removed. New elements are added to the back/rear of the queue.
88
*/
99
class Queue {
@@ -153,7 +153,7 @@ public static void main(String[] args) {
153153
myQueue.remove(); // Will make 2 the new front, making 10 no longer part of the queue
154154
// [10, 2(front), 5, 3(rear)]
155155

156-
myQueue.insert(7); // Insert 7 at the rear which will be index 0 because of wrap around
156+
myQueue.insert(7); // Insert 7 at the rear which will get 0 index because of wrap around
157157
// [7(rear), 2(front), 5, 3]
158158

159159
System.out.println(myQueue.peekFront()); // Will print 2

0 commit comments

Comments
 (0)