-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Algo] Adding Heap sort [Java] #509
Conversation
This commit adds heap_sort.java, which includes an Java implementation of the Heap sort algorithm, using a custom Heap data structure. Closes NITSkmOS#508
heap_sort/java/heap_sort.java
Outdated
heap.removeMin(); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
Origin: SpaceConsistencyBear, Section: all.pyjava
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -10,7 +10,7 @@
heap.removeMin();
}
}
-
+
public static void main(String[] args) {
int[] arr = new int[] {2, 3, 0, 4, -1, 34, 10, 12, 6, -10};
run_heap_sort(arr);
heap_sort/java/heap_sort.java
Outdated
System.out.println(element); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
Origin: SpaceConsistencyBear, Section: all.pyjava
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -18,7 +18,7 @@
System.out.println(element);
}
}
-
+
private static class HeapMin {
private int actualSize, maxSize;
private int[] nodes;
heap_sort/java/heap_sort.java
Outdated
return 0; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
Origin: SpaceConsistencyBear, Section: all.pyjava
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -85,7 +85,7 @@
return 0;
}
}
-
+
/**
* Rises a heap element
* @param i Element index
heap_sort/java/heap_sort.java
Outdated
int aux = nodes[parent(i)]; | ||
nodes[parent(i)] = nodes[i]; | ||
nodes[i] = aux; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
Origin: SpaceConsistencyBear, Section: all.pyjava
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -98,7 +98,7 @@
int aux = nodes[parent(i)];
nodes[parent(i)] = nodes[i];
nodes[i] = aux;
-
+
rise(parent(i));
}
}
heap_sort/java/heap_sort.java
Outdated
} | ||
}else if (leftChild(i) != 0){ | ||
child = leftChild(i); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
Origin: SpaceConsistencyBear, Section: all.pyjava
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -127,7 +127,7 @@
}
}else if (leftChild(i) != 0){
child = leftChild(i);
- }
+ }
//If there's a child node, try to switch node positions
if(child > 0){
heap_sort/java/heap_sort.java
Outdated
}else if (leftChild(i) != 0){ | ||
child = leftChild(i); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
Origin: SpaceConsistencyBear, Section: all.pyjava
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -128,7 +128,7 @@
}else if (leftChild(i) != 0){
child = leftChild(i);
}
-
+
//If there's a child node, try to switch node positions
if(child > 0){
if(nodes[child] < nodes[i]){
heap_sort/java/heap_sort.java
Outdated
int aux = nodes[i]; | ||
nodes[i] = nodes[child]; | ||
nodes[child] = aux; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
Origin: SpaceConsistencyBear, Section: all.pyjava
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -135,7 +135,7 @@
int aux = nodes[i];
nodes[i] = nodes[child];
nodes[child] = aux;
-
+
descend(child);
}
}
heap_sort/java/heap_sort.java
Outdated
descend(1); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
Origin: SpaceConsistencyBear, Section: all.pyjava
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -164,7 +164,7 @@
descend(1);
}
}
-
+
}
}```
heap_sort/java/heap_sort.java
Outdated
|
||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains following spacing inconsistencies:
- No newline at EOF.
Origin: SpaceConsistencyBear, Section: all.pyjava
.
The issue can be fixed by applying the following patch:
--- a/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
+++ b/tmp/tmpf8ywa7q7/heap_sort/java/heap_sort.java
@@ -167,4 +167,4 @@
}
-}+}
There was some trailing whitespace on heap_sort.java, so I removed it in the second commit here. |
Invalid? Why? |
Go through the CONTRIBUTING guideline. |
Adds heap_sort.java, which includes an Java implementation of the Heap sort algorithm, using a custom Heap data structure.
Closes #508
By submitting this pull request I confirm I've read and complied with the
below declarations.
{Tag}: Add {Algorithm/DS name} [{Language}]
, notUpdate README.md
orAdded new code
.After you submit your pull request, DO NOT click the 'Update Branch' button.