This commit is contained in:
Abhinandan Padmakar Pandey
2021-10-08 22:02:34 +05:30
committed by GitHub
parent 4a8357651d
commit 9b38ecdfa6
3 changed files with 18 additions and 18 deletions

View File

@ -5,17 +5,17 @@ import java.util.ArrayList;
/**
* This class implements a GenericArrayListQueue.
*
* <p>A GenericArrayListQueue data structure functions the same as any specific-typed queue. The
* GenericArrayListQueue holds elemets of types to-be-specified at runtime. The elements that are
* added first are the first to be removed (FIFO) New elements are added to the back/rear of the
* A GenericArrayListQueue data structure functions the same as any specific-typed queue. The
* GenericArrayListQueue holds elements of types to-be-specified at runtime. The elements that are
* added first are the first to be removed (FIFO). New elements are added to the back/rear of the
* queue.
*/
public class GenericArrayListQueue<T> {
/** The generic ArrayList for the queue T is the generic element */
ArrayList<T> _queue = new ArrayList<T>();
ArrayList<T> _queue = new ArrayList<>();
/**
* Checks if the queue has elements (not empty)
* Checks if the queue has elements (not empty).
*
* @return True if the queue has elements. False otherwise.
*/
@ -24,7 +24,7 @@ public class GenericArrayListQueue<T> {
}
/**
* Checks what's at the front of the queue
* Checks what's at the front of the queue.
*
* @return If queue is not empty, element at the front of the queue. Otherwise, null
*/
@ -51,7 +51,7 @@ public class GenericArrayListQueue<T> {
*
* @return If queue is not empty, element retrieved. Otherwise, null
*/
public T poll() {
public T pull() {
T result = null;
if (this.hasElements()) {
result = _queue.remove(0);
@ -65,19 +65,19 @@ public class GenericArrayListQueue<T> {
* @param args Command line arguments
*/
public static void main(String[] args) {
GenericArrayListQueue<Integer> queue = new GenericArrayListQueue<Integer>();
GenericArrayListQueue<Integer> queue = new GenericArrayListQueue<>();
System.out.println("Running...");
assert queue.peek() == null;
assert queue.poll() == null;
assert queue.add(1) == true;
assert queue.pull() == null;
assert queue.add(1);
assert queue.peek() == 1;
assert queue.add(2) == true;
assert queue.add(2);
assert queue.peek() == 1;
assert queue.poll() == 1;
assert queue.pull() == 1;
assert queue.peek() == 2;
assert queue.poll() == 2;
assert queue.pull() == 2;
assert queue.peek() == null;
assert queue.poll() == null;
assert queue.pull() == null;
System.out.println("Finished.");
}
}