Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <ctime>
- using namespace std;
- void sort(int *a,int n){
- if (n>1){
- int l=0,r=n - 1;
- int c=a[rand()%n];
- do{
- while(a[l]<c){
- l++;
- }
- while(a[r]>c){
- r--;
- }
- if (l<=r){
- swap(a[l++],a[r--]);
- }
- } while(l <= r);
- sort(a,r+1);
- sort(a+l,n-l);
- }
- }
- int main()
- {
- int n=7;
- while(true) {
- cin >> n;
- int a[n];
- for(int i = 0; i < n; i++ ){
- a[i] = rand() % 100;
- }
- sort(a,n);
- for(int i=0;i<n;i++){
- cout<<a[i] << " ";
- }
- cout << endl;
- }
- }
Add Comment
Please, Sign In to add comment