Created
July 8, 2020 12:24
-
-
Save BMU-Verlag/187b5c0bdeb01621ceddd4375fe57056 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int tausch = arr[position]; | |
arr[position] = arr[groesstesElement]; | |
arr[groesstesElement] = tausch; | |
heapify(arr, groesse, groesstesElement); | |
Damit ist auch diese Funktion abgeschlossen. Ihr Code sieht so aus: | |
void heapify(int arr[], int groesse, int position) { | |
int groesstesElement = position; | |
int links = 2 * position + 1; | |
int rechts = 2 * position + 2; | |
if (links < groesse && arr[links] > arr[groesstesElement]){ | |
groesstesElement = links; | |
} | |
if (rechts < groesse && arr[rechts] > arr[groesstesElement]){ | |
groesstesElement = rechts; | |
} | |
if (groesstesElement != position) { | |
int tausch = arr[position]; | |
arr[position] = arr[groesstesElement]; | |
arr[groesstesElement] = tausch; | |
heapify(arr, groesse, groesstesElement); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment