quicksort 2



  • #include <iostream>
    #include <algorithm>
    #include <vector>
    
    using namespace std;
    
    int partition(int a[], int left, int right)
    {
    	int pivot = a[left];
    	while (true)
    	{
    		while (a[left] < pivot) left++;
    		while (a[right] > pivot) right--;
    		if (left < right)
    		{
    			swap(a[left], a[right]);
    		}
    		else
    		{
    			return right;
    		}
    	}
    }
    
    void quicksort(int a[], int left, int right)
    {
    	if (left < right)
    	{
    		int pivot = partition(a, left, right);
     quicksort(a, left, pivot-1);  //Warum findet hier kein Aufruf statt. pivot=0! 
    	//	quicksort(a, pivot+1, right);
    	}
    }
    
    void main(void)
    {
    
    	int thearray[]={2 ,15, 9 ,5}; 
    
    	quicksort(thearray,0,3);
    
    	for (int i=0; i<4; ++i)
    	{
    		cout << thearray[i] << " ";
    	}
    	cout << endl;
    
    }
    


  • sry hat sich schon erledigt. Es tritt die Abbruchbedingung in Kraft.


Anmelden zum Antworten