Skip to content

Commit 12d2404

Browse files
authored
Update GenericArrayListQueue.java
Documentations added
1 parent a3e0cf8 commit 12d2404

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

DataStructures/Queues/GenericArrayListQueue.java

+39
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,68 @@
22

33
import java.util.ArrayList;
44

5+
/**
6+
* This class implements a GenericArrayListQueue.
7+
* <p>
8+
* A GenericArrayListQueue data structure functions the same as any specific-typed queue.
9+
* The GenericArrayListQueue holds elemets of types to-be-specified at runtime.
10+
* The elements that are added first are the first to be removed (FIFO)
11+
* New elements are added to the back/rear of the queue.
12+
*
13+
*/
514
public class GenericArrayListQueue<T> {
15+
/**
16+
* The generic ArrayList for the queue
17+
* T is the generic element
18+
*/
619
ArrayList<T> _queue = new ArrayList<T>();
720

21+
/**
22+
* Checks if the queue has elements (not empty)
23+
*
24+
* @return True if the queue has elements. False otherwise.
25+
*/
826
private boolean hasElements() {
927
return !_queue.isEmpty();
1028
}
1129

30+
/**
31+
* Checks what's at the front of the queue
32+
*
33+
* @return If queue is not empty, element at the front of the queue. Otherwise, null
34+
*/
1235
public T peek() {
1336
T result = null;
1437
if(this.hasElements()) { result = _queue.get(0); }
1538
return result;
1639
}
1740

41+
/**
42+
* Inserts an element of type T to the queue.
43+
*
44+
* @param element of type T to be added
45+
* @return True if the element was added successfully
46+
*/
1847
public boolean add(T element) {
1948
return _queue.add(element);
2049
}
2150

51+
/**
52+
* Retrieve what's at the front of the queue
53+
*
54+
* @return If queue is not empty, element retrieved. Otherwise, null
55+
*/
2256
public T poll() {
2357
T result = null;
2458
if(this.hasElements()) { result = _queue.remove(0); }
2559
return result;
2660
}
2761

62+
/**
63+
* Main method
64+
*
65+
* @param args Command line arguments
66+
*/
2867
public static void main(String[] args) {
2968
GenericArrayListQueue<Integer> queue = new GenericArrayListQueue<Integer>();
3069
System.out.println("Running...");

0 commit comments

Comments
 (0)