Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1f91a98

Browse files
refactoring
1 parent 39be70c commit 1f91a98

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

‎src/main/java/ir/sk/adt/datastructure/tree/binarytree/heaptree/MaxBinaryHeap.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public int max() {
9191
@TimeComplexity("O(Log n)")
9292
public int extractMax() {
9393
int max = array[0];
94-
swap(0, size - 1);
94+
swapWithIndex(0, size - 1);
9595
array[size - 1] = 0; // Avoid loitering.
9696

9797
heapifyDown(0);
@@ -119,7 +119,7 @@ public void heapifyDown(int index) {
119119
maxIndex = right;
120120

121121
if (maxIndex != index) {
122-
swap(index, maxIndex);
122+
swapWithIndex(index, maxIndex);
123123
heapifyDown(maxIndex);
124124
}
125125
}
@@ -149,12 +149,12 @@ private void heapifyUp() {
149149
int current = size;
150150

151151
while (array[current] > array[getParentIndex(current)]) {
152-
swap(current, getParentIndex(current));
152+
swapWithIndex(current, getParentIndex(current));
153153
current = getParentIndex(current);
154154
}
155155
}
156156

157-
private void swap(int index1, int index2) {
157+
private void swapWithIndex(int index1, int index2) {
158158
int tmp = array[index1];
159159
array[index1] = array[index2];
160160
array[index2] = tmp;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /