File tree Expand file tree Collapse file tree 3 files changed +17
-5
lines changed
Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ public DynamicArrayQueue(int capacity) {
2626 *
2727 * @return true if the queue has no elements, false otherwise.
2828 */
29+ @ Override
2930 public boolean isEmpty () {
3031 return size == 0 ;
3132 }
@@ -35,6 +36,7 @@ public boolean isEmpty() {
3536 *
3637 * @param value The character to add.
3738 */
39+ @ Override
3840 public void enqueue (char value ) {
3941 if (size == data .length ) {
4042 // Double the size of the array when
@@ -52,6 +54,7 @@ public void enqueue(char value) {
5254 * @return The character at the front of the queue.
5355 * @throws NoSuchElementException if the queue is empty.
5456 */
57+ @ Override
5558 public char dequeue () {
5659 if (isEmpty ()) {
5760 throw new NoSuchElementException ("Queue is empty" );
@@ -71,6 +74,7 @@ public char dequeue() {
7174 /**
7275 * Returns the character at the front of the queue without removing it.
7376 */
77+ @ Override
7478 public char peek () {
7579 if (isEmpty ()) {
7680 throw new NoSuchElementException ("Queue is empty" );
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ private static class Node {
2828 *
2929 * @return true if the queue has no elements, false otherwise.
3030 */
31+ @ Override
3132 public boolean isEmpty () {
3233 return front == null ;
3334 }
@@ -37,6 +38,7 @@ public boolean isEmpty() {
3738 *
3839 * @param value The character to add.
3940 */
41+ @ Override
4042 public void enqueue (char value ) {
4143 Node newNode = new Node (value );
4244 if (isEmpty ()) {
@@ -53,6 +55,7 @@ public void enqueue(char value) {
5355 * @return The character at the front of the queue.
5456 * @throws NoSuchElementException if the queue is empty.
5557 */
58+ @ Override
5659 public char dequeue () {
5760 if (isEmpty ()) {
5861 throw new NoSuchElementException ("Queue is empty" );
@@ -68,6 +71,7 @@ public char dequeue() {
6871 /**
6972 * Returns the character at the front of the queue without removing it.
7073 */
74+ @ Override
7175 public char peek () {
7276 if (isEmpty ()) {
7377 throw new NoSuchElementException ("Queue is empty" );
Original file line number Diff line number Diff line change @@ -17,21 +17,22 @@ public class StaticArrayQueue implements Queue {
1717 /**
1818 * Constructs a new Queue with a specified capacity.
1919 */
20- public StaticArrayQueue (int capacity ) {
21- if (capacity < 1 ) {
22- throw new IllegalArgumentException ("Capacity must be at least 1" );
20+ public StaticArrayQueue (int size ) {
21+ if (size < 1 ) {
22+ throw new IllegalArgumentException ("Size must be at least 1" );
2323 }
24- data = new char [capacity ];
24+ data = new char [size ];
2525 front = 0 ;
2626 rear = -1 ;
27- size = 0 ;
27+ this . size = 0 ;
2828 }
2929
3030 /**
3131 * Checks if the queue is empty.
3232 *
3333 * @return true if the queue has no elements, false otherwise.
3434 */
35+ @ Override
3536 public boolean isEmpty () {
3637 return size == 0 ;
3738 }
@@ -50,6 +51,7 @@ public boolean isFull() {
5051 *
5152 * @param value The character to add.
5253 */
54+ @ Override
5355 public void enqueue (char value ) {
5456 if (isFull ()) {
5557 throw new IllegalStateException ("Queue is full" );
@@ -65,6 +67,7 @@ public void enqueue(char value) {
6567 * @return The character at the front of the queue.
6668 * @throws NoSuchElementException if the queue is empty.
6769 */
70+ @ Override
6871 public char dequeue () {
6972 if (isEmpty ()) {
7073 throw new NoSuchElementException ("Queue is empty" );
@@ -78,6 +81,7 @@ public char dequeue() {
7881 /**
7982 * Returns the character at the front of the queue without removing it.
8083 */
84+ @ Override
8185 public char peek () {
8286 if (isEmpty ()) {
8387 throw new NoSuchElementException ("Queue is empty" );
You can’t perform that action at this time.
0 commit comments