#include "stdafx.h"
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
 
//const int n = 7;
//int a[n] = { 20, 7, 15, 1, 3, 10, 12 };
 
 const int n = 1000000;
int a[n];
 
void swap (int i, int k)
{
    int c;
    c = a[i];
    a[i] = a[k];
    a[k] = c;
}
 
void quickSort (int r, int s)
{
    int i=r;
    int k=s;
    int h=a[(i+k)/2];
    while (i <= k)
    {
        while (h > a[i]) i++;
        while (h < a[k]) k--;
        if (i <= k)
        {
            swap (i, k);
            i++;
            k--;
        }
    }
    if(r<k) quickSort (r, k);
    if(i<s) quickSort (i, s);
 
 
}
 
int main (int argc, char * argv[])
{
 
    srand (time (nullptr));
    for (int i = 0; i < n; i++)
        a[i] = rand () % 10000;
 
 
    quickSort (0, n-1);
 
    for (int i = 0; i < n; i++)
    {
       // cout << a[i];
        if (i > 0)
            if (a[i - 1] > a[i])
                cout << " Chyba";
        //cout << endl;
    }
 
    cout << "Konec programu" << endl;
    system ("pause");
    return 0;
}
 
quicksort_ut.txt · Last modified: 2018/04/24 18:19 by 147.32.8.110
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki