Skip to content

Commit 72b3d9f

Browse files
author
Lord-of-Algorithms
committed
Refactor constructors to use 'capacity' instead of 'size' in StaticArrayQueue and StaticArrayStack
1 parent f5648ad commit 72b3d9f

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/lineards/queue/StaticArrayQueue.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ public class StaticArrayQueue implements Queue {
1515
private int size;
1616

1717
/**
18-
* Constructs a new Queue with a specified capacity.
18+
* Constructs a new queue with a specified capacity.
19+
*
20+
* @param capacity The maximum number of items that the queue can hold.
1921
*/
20-
public StaticArrayQueue(int size) {
21-
if (size < 1) {
22-
throw new IllegalArgumentException("Size must be at least 1");
22+
public StaticArrayQueue(int capacity) {
23+
if (capacity < 1) {
24+
throw new IllegalArgumentException("Capacity must be at least 1");
2325
}
24-
data = new char[size];
26+
data = new char[capacity];
2527
front = 0;
2628
rear = -1;
27-
this.size = 0;
29+
size = 0;
2830
}
2931

3032
/**

src/lineards/stack/StaticArrayStack.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ public class StaticArrayStack implements Stack {
1313
private int top;
1414

1515
/**
16-
* Constructor to initialize the stack with a given size.
16+
* Constructor to initialize the stack with a given capacity.
17+
*
18+
* @param capacity The maximum number of items that the stack can hold.
1719
*/
18-
public StaticArrayStack(int size) {
19-
if (size < 1) {
20-
throw new IllegalArgumentException("Size must be at least 1");
20+
public StaticArrayStack(int capacity) {
21+
if (capacity < 1) {
22+
throw new IllegalArgumentException("Capacity must be at least 1");
2123
}
22-
data = new char[size];
24+
data = new char[capacity];
2325
top = -1;
2426
}
2527

0 commit comments

Comments
 (0)