Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <iostream>
- using namespace std;
- int n, arr[100];
- void swap_int( int *a, int *b ) {
- int temp = *a;
- *a = *b;
- *b = temp;
- }
- void q_sort(int f, int l) {
- if( f>=l ) return;
- int i=f+1, j=l;
- do {
- while( arr[i]<arr[f] ) i++;
- while( arr[j]>arr[f] ) j--;
- if( i<j ) swap_int( &arr[i], &arr[j] );
- } while( i<j );
- swap_int( &arr[f], &arr[j] );
- q_sort( f, j-1 );
- q_sort( j+1, l );
- }
- int main() {
- cin>>n;
- for( int i=0; i<n; i++ ) cin>>arr[i];
- q_sort(0,n-1);
- for( int i=0; i<n; i++ ) cout << arr[i] << " "; cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement