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.

bubble sort - c++

Empfohlene Antworten

Hallo zamm,

ich brauche ein

paar Beispiele für

bubble sorts.

Zum Beispiel für die

Sortierung eines arrays

oder eines arrays, auf das

ein pointer zeigt.

wenn ich da

was zusammen geschrieben

habe, dann wird es zwar compiliert,

aber an dem Punkt, wo es sortieren soll,

kommt dann invalid floating point,

oder so was.

Gruß

und Danke

nins

mein proggie erzeugt einen zufallsarray (arr1) und kopiert diesen in arr2,

dieser wird dann per funktion sortiert

#include <condefs>

#include <conio>

#include <iostream>

#include <stdlib>

#include <iomanip>

using namespace std;

int arr1[50];

int arr2[50];

//---------------------------------------------------------------------------

void generate(int);

void sort(int);

void main()

{

int a;

int Z=50;

clrscr();

// cout << " Wieviele Zufallszahlen ?";

// cin >> Z;

randomize();

generate(Z);

for (a=0; a <= (Z-1);a++)

arr2[a]=arr1[a];

cout << fixed << setw(4);

for(a=0; a<=(Z-1); a++)

{

if ((a%20==0) && (a!=0))

{

getch();

clrscr();

}

cout << setw(4) << a << ": " << setw(4) << arr1[a] << " " << setw(4) << arr2[a] << endl;

}

sort(Z);

getch();

clrscr();

for(a=0; a<=(Z-1); a++)

{

if ((a%20==0) && (a!=0))

{

getch();

clrscr();

}

cout << setw(4) << a << ": " << setw(4) << arr1[a] << " " << setw(4) << arr2[a] << endl;

}

getch();

}

void generate(int B)

{

for(int a=0; a<=(b-1); a++)

{

arr1[a]=(random(100)+1);

}

}

void sort(int A)

{

int d;

for (int i = 0; i <= (A-1); i++)

{

for (int j = (A-1); j > i; j--)

{

if (arr2 >= arr2[j])

{

d = arr2;

arr2 = arr2[j];

arr2[j] = d;

}

}

}

}

  • 5 Jahre später...

Super, vielen Dank.

Gibt es noch ein Buch, welches die Sortieralgorithmen erklärt?

Kann man da was empfehlen?

SelectionSort und Co lassen Grüssen. ;)

Das werde ich mir mal näher anschauen, vielen Dank.

Ja, alt ist das Thema schon, aber unsere Lehrer hält es immernoch für so frisch, dass man es nochmal aufwärmen kann. ;)

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

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.