Skip to content

Commit 7ddcefc

Browse files
committed
fixed heap sort
1 parent 2baafbe commit 7ddcefc

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

Assets/Scripts/ArrayController.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,14 @@ IEnumerator HeapSort(int[] arr) {
568568
arr[0] = arr[i];
569569
arr[i] = temp;
570570

571-
pillars[i].GetComponent<Pillar>().Color = checkColor;
571+
pillars[i].GetComponent<Pillar>().Color = nextColor;
572+
if (i+1 < arr.Length) {
573+
pillars[i + 1].GetComponent<Pillar>().Color = checkColor;
574+
575+
}
572576

573577
for (int j = 0; j < arr.Length; j++) {
574-
if (pillars[j].GetComponent<Pillar>().Color != checkColor) {
578+
if (pillars[j].GetComponent<Pillar>().Color != checkColor && pillars[j].GetComponent<Pillar>().Color != nextColor) {
575579
pillars[j].GetComponent<Pillar>().Color = whiteColor;
576580
}
577581
}
@@ -613,7 +617,7 @@ IEnumerator heapify(int[] arr, int N, int i) {
613617
arr[i] = arr[largest];
614618
arr[largest] = swap;
615619

616-
pillars[largest].GetComponent<Pillar>().Color = nextColor;
620+
pillars[largest].GetComponent<Pillar>().Color = swapColor;
617621

618622
// Recursively heapify the affected sub-tree
619623
yield return heapify(arr, N, largest);

docs/Build/docs.data

0 Bytes
Binary file not shown.

docs/Build/docs.wasm

130 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)