Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void quicksort( double array[], long long left, long long right);
- long long partition( double array[], long long left, long long right);
- int fDig( double x);
- int main( void) {
- long long quantity = 0LL, counter = 0LL;
- int dig = 0;
- scanf("%lli", &quantity);
- double beard[quantity];
- for( counter = 0LL; counter < quantity; counter++) {
- scanf("%lf", &beard[counter]);
- }
- quicksort( beard, 0LL, quantity - 1LL);
- for( counter = 0LL; counter < quantity; counter++) {
- dig = fDig( beard[counter]);
- printf("%.*lf", dig, beard[counter]);
- if( counter == quantity - 1LL) {
- break;
- }
- printf(" ");
- }
- return 0;
- }
- int fDig( double x) {
- int result = 0;
- while( x != floor(x)) {
- x *= 10;
- result++;
- }
- return result;
- }
- /* Quick sort recursive function */
- void quicksort( double array[], long long left, long long right){
- if ( left < right) {
- long long middle = partition( array, left, right);
- quicksort( array, left, middle - 1LL);
- quicksort( array, middle + 1LL, right);
- }
- }
- /* Partition :
- Modifies the array :
- SMALLER , PIVOT , GREATER
- Returns the index for pivot because pivot is placed in the final position
- */
- long long partition( double array[], long long left, long long right) {
- long long middle;
- double x = array[left];
- long long l = left;
- long long r = right;
- while( l < r) {
- while( ( array[l] <= x) && ( l < right)) {
- l++;
- }
- while( ( array[r] > x) && ( r >= left)) {
- r--;
- }
- if( l < r) {
- double temp = array[l];
- array[l] = array[r];
- array[r] = temp;
- }
- }
- middle = r;
- double temp = array[left];
- array[left] = array[middle] ;
- array[middle] = temp;
- return middle ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement