Answer to Question #236510 in C for shivam

Question #236510

Write a program to sort an array of floating-point numbers in descending order using the quick sort?


1
Expert's answer
2021-09-13T18:30:13-0400
#include <stdio.h>
#include <stdlib.h>


void quick_sort(int arr[], int l, int r)
    {
      int i = l;
      int j = r;
      int temp = arr[i];


      if( l < r)
        {
             while(i < j)
             {
                    while(arr[j] <= temp && i < j)
                    {
                           j--;
                    }
                    arr[i] = arr[j];


             while(arr[i] >= temp && i < j)
                    {
                           i++;
                    }
                    arr[j] = arr[i];
             }
             arr[i] = temp;


            quick_sort(arr, l, i - 1);
            quick_sort(arr, j + 1, r);
            }
       }


void main()
       {
              int arr[8] = {23, 51, 22, 11, 9, 43, 36, 107};
              quick_sort(arr, 0, 7);


       int i;
        printf("\nSorted Array:\n");
              for (i = 0; i < 8; i++)
                     printf("%d \t",arr[i]);
              printf("\n");
       }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS