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 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.

Schon durchgelesen. Schon gegoogelt.

Mit meinem Wissensstandart aus der Schule kann ich kein Rekursives Quicksort schreiben. Darum muss ich leider ein Iteratives schreiben. Jedoch wie?

Das ist meine Frage.

Mit meinem Wissensstandart aus der Schule kann ich kein Rekursives Quicksort schreiben. Darum muss ich leider ein Iteratives schreiben.
Ich halte die iterative Implementierung für viel komplizierter als die rekursive, weil du dich dann selbst um eine Stapel-Datenstruktur kümmern musst, die den Zustand speichert.

Klär das besser nochmal mit dem Referat-"Vergeber".

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.