Ich bin Anfänger in C++.
Ich soll für ein Referat ein Beispielprojekt mit einem Quicksort Algorithmus schreiben.
Soweit bin ich gekommen:
#include <iostream>
#include <iomanip>
#include <conio.h>
using namespace std;
int main() {
int wuerfel[10], swap;
for (int idx = 0; idx <= 9; idx++)
{
cout << "Geben Sie die " << idx+1 << ". gewuerfelte Zahl ein: ";
cin >> wuerfel[idx];
}
cout << endl << "unsortierte Zahlen: " << endl;
for (int idx = 0; idx <= 9; idx++)
{
cout << wuerfel[idx] << " ";
}
cout << endl << endl;
int i = 0, j = 9;
int x = wuerfel[(9 / 2)];
while (i <= j)
{
while (wuerfel[i] < x) i++;
while (wuerfel[j] > x) j--;
if (i <= j)
{
swap = wuerfel[i];
wuerfel[i] = wuerfel[j];
wuerfel[j] = swap;
i++;
j--;
}
}
cout << "sortierte Zahlen: " << endl;
for (int idx = 0; idx <= 9; idx++)
{
cout << wuerfel[idx] << " ";
}
getch();
return 0;
}
Jedoch finde ich meinen Fehler nicht.
Könnt ihr mir bitte helfen?
Es werden die Zahlen nicht richtig sortiert.