Skip to content

Commit 472ab01

Browse files
committed
rename temp[] to copy[] in resizing array code
1 parent cfc6001 commit 472ab01

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/main/java/edu/princeton/cs/algs4/ResizingArrayBag.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ public int size() {
6060
// resize the underlying array holding the elements
6161
private void resize(int capacity) {
6262
assert capacity >= n;
63-
Item[] temp = (Item[]) new Object[capacity];
63+
Item[] copy = (Item[]) new Object[capacity];
6464
for (int i = 0; i < n; i++)
65-
temp[i] = a[i];
66-
a = temp;
65+
copy[i] = a[i];
66+
a = copy;
6767
}
6868

6969
/**

src/main/java/edu/princeton/cs/algs4/ResizingArrayQueue.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ public int size() {
7272
// resize the underlying array
7373
private void resize(int capacity) {
7474
assert capacity >= n;
75-
Item[] temp = (Item[]) new Object[capacity];
75+
Item[] copy = (Item[]) new Object[capacity];
7676
for (int i = 0; i < n; i++) {
77-
temp[i] = q[(first + i) % q.length];
77+
copy[i] = q[(first + i) % q.length];
7878
}
79-
q = temp;
79+
q = copy;
8080
first = 0;
8181
last = n;
8282
}

src/main/java/edu/princeton/cs/algs4/ResizingArrayStack.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ private void resize(int capacity) {
7474
assert capacity >= n;
7575

7676
// textbook implementation
77-
Item[] temp = (Item[]) new Object[capacity];
77+
Item[] copy = (Item[]) new Object[capacity];
7878
for (int i = 0; i < n; i++) {
79-
temp[i] = a[i];
79+
copy[i] = a[i];
8080
}
81-
a = temp;
81+
a = copy;
8282

8383
// alternative implementation
8484
// a = java.util.Arrays.copyOf(a, capacity);

0 commit comments

Comments
 (0)