Skip to content

Instantly share code, notes, and snippets.

@BMU-Verlag
Created July 8, 2020 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BMU-Verlag/187b5c0bdeb01621ceddd4375fe57056 to your computer and use it in GitHub Desktop.
Save BMU-Verlag/187b5c0bdeb01621ceddd4375fe57056 to your computer and use it in GitHub Desktop.
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