Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <ctime>
- using namespace std;
- void swap(int a,int b){
- int c;
- c = a;
- a = b;
- b = c;
- }
- void qsort1 (int *a, int n){
- if (n > 1){
- int l = 0;
- int r = n - 1;
- int c = a[rand()%n];
- while ( l < r ) {
- while (a[l] < c){
- l++;
- }
- while (a[r] > c){
- r--;
- }
- }
- if (l <= r)
- swap (a[l++], a[r--]);
- while ()
- qsort1 (a, n + 1);
- qsort1 (a + l, n - l);
- }
- }
- int main()
- {
- int n = 8;
- int a[n] = {0,9,76,5,6,4,24,1};
- qsort1 (a,n);
- for (int i = 0; i < n; i++)
- cout << a[i] << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement