Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Ich frag mich die ganze Zeit, warum Bubblesort. Ist doch eher eins der langsamen. Da kann man doch gleich Quicksort nehmen. Das ist sogar in der Standard Library :


int compare_ints( const void* a, const void* b ) {
int* arg1 = (int*) a;
int* arg2 = (int*) b;
if( *arg1 < *arg2 ) return -1;
else if( *arg1 == *arg2 ) return 0;
else return 1;
}
...
qsort( array, array_size, sizeof(int), compare_ints );
[/PHP]

(geklaut aus http://www.cppreference.com/stdother/qsort.html)

Ehrlich gesagt, für das Problem nehm ich auch lieber die von Eytibi genannte Lösungsart.

Bubblesort nimmt man doch normalerweise nur, um zu lernen, wie Sortieren funktioniert. Nicht für Min / Max Aufgaben.

Jaja, war ja auch nur Hinweis.

In dem Fall wäre die Geschwindikeit eh nicht wichtig, zu wenig Elemente für ein großen Unterschied (Quicksort's Zeitverhalten nähert sich dann auch der n² des Bubblesort an). Aber bei mehr Elementen eines Int Arrays wäre Quicksort auf jeden Fall vorzuziehen (normalerweise n*log(n), worst case n²). Bei ganz großen Mengen ist Heapsort auch Klasse. (auch angegeben mit n*log(n)).

Beim Sortieren von anderen Listen können andere Algorithmen schneller sein, da dort auch die Zugriffzeiten und Speicherverbrauch usw wichtig sind.

Ich habe allerdings noch keinen sinnvollen Einsatz von Bubblesort gesehen, wo es Quicksort nicht besser gemacht hätte.

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.