Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int t[35], d;
- int qsearch ( int L, int P , int k )
- {
- int m = L;
- for ( int i = m+1; i <= P; i++ )
- if ( t[i] < t[L] ) swap ( t[++m], t[i] );
- swap ( t[L], t[m] );
- if ( m - L + 1 == k ) return t[m];
- if ( m - L + 1 > k ) return qsearch ( L, m - 1, k );
- if ( m - L + 1 < k ) return qsearch ( m + 1, P, k - ( m - L + 1 ) );
- }
- int main()
- {
- srand(time(NULL));
- for ( int i = 0; i < 30; i++ )
- t[i] = rand() %90 +10;
- for ( int i = 0; i < 30; i++ )
- cout << t[i] << " ";
- cout << endl;
- for ( int i = 0; i < 30; i++ )
- {
- cout << qsearch( 0, 29, i + 1 ) << " ";
- random_shuffle( t, t + 29 );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement