// QuickSort.cpp : 
 
#include "stdafx.h"
#include <string>
#include <iostream>
#include <cstdlib>
using namespace std;
 
const int N = 200;
int a[N];
 
void QuickSort (int L, int P){
 
	int i = L;
	int k = P;
	int h= a[(L+P)/2];
 
	while(i <= k){
		while ( a[i] < h) i++;
		while ( a[k] > h) k--;
		if (i<=k)
		{
  		   int p = a[i];
		   a[i] = a[k];
		   a[k] = p;
		   i++;
		   k--;
		}
	}
 
	if (L<k) QuickSort(L , k);
	if (i<P) QuickSort(i , P);
}
 
void print()
{
	for (int i = 0; i< N; i++)
	{
		if (i < N-1)
			if (a[i] > a[i+1]) cout << "chyba" <<endl;
		cout << a[i] << ", ";
	}
	cout << endl;
}
 
int _tmain(int argc, _TCHAR* argv[])
{
	srand(0);
	for (int i=0; i< N; i++)
		a[i] = rand() %100;
 
	QuickSort (0, N-1);
	print ();
 
	cout << "Konec - stisknete enter" << endl;
 
	char c;
	cin >> c;
 
	return 0;
}
 
quicksort_c.txt · Last modified: 2015/05/07 15:40 by 147.32.8.115
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki