File tree Expand file tree Collapse file tree
src/main/java/org/alda/structure/queue/array Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package org .alda .structure .queue .array ;
2+
3+ import org .alda .structure .queue .IQueue ;
4+
5+ import java .util .ArrayList ;
6+
7+ /**
8+ * @author bcExpt1123
9+ *
10+ * Implementation of a generic Queue using an ArrayList.
11+ * @param <T>
12+ */
13+ public class QueueArray <T > implements IQueue <T > {
14+ /**
15+ * Internal storage for the queue elements.
16+ */
17+ public ArrayList <T > items ;
18+
19+ public QueueArray () {
20+ items = new ArrayList <>();
21+ }
22+
23+ /**
24+ * {@inheritDoc}
25+ * @return
26+ */
27+ public boolean isEmpty () {
28+ return items .isEmpty ();
29+ }
30+
31+ /**
32+ * {@inheritDoc}
33+ * @param item the item to be added.
34+ */
35+ public void enqueue (T item ) {
36+ items .add (item );
37+ }
38+
39+ /**
40+ * {@inheritDoc}
41+ * @return
42+ */
43+ public T dequeue () {
44+ if (items .isEmpty ()) {
45+ return null ;
46+ }
47+ return items .removeLast ();
48+ }
49+
50+ /**
51+ * {@inheritDoc}
52+ * @return
53+ */
54+ public T front () {
55+ if (items .isEmpty ()) {
56+ return null ;
57+ }
58+ return items .getFirst ();
59+ }
60+
61+ /**
62+ * {@inheritDoc}
63+ * @return
64+ */
65+ public T rear (){
66+ if (items .isEmpty ()) {
67+ return null ;
68+ }
69+ return items .getLast ();
70+ }
71+ }
You can’t perform that action at this time.
0 commit comments