Answered! 1 b. Modify the QUICKSORT and PARTITION procedures to sort in decreasing order….

1 b. Modify the QUICKSORT and PARTITION procedures to sort in decreasing order.

QUICK SORT(A, p, r) 1 if p <r 2 q PARTITION A, p, r) QUICKSORT(A, p, q QUICKSORT(A, q 1, r) To sort an entire array A. the initial call is QUICKSORT(A, 1, A. length) Partitioning the array The key to the algorithm is the PARTITION procedure, which rearranges the subar- ray Alp ..rl in place. PARTITION (A, p, r) Air] 1 2 i 3 for j p to r -1 4 if Aljlsx i I exchange A with A 7 exchange Ali ij with AIrl 8 return. i 1

Expert Answer

 #include <stdio.h>

int main(void)

{

int a[10], i=0, j=0, n, t;

printf (“n Enter the no. of elements: “);

scanf (“%d”, &n);

printf (“n”);

for (i = 0; i <n; i++)

{

printf (“n Enter the %dth element: “, (i+1));

scanf (“%d”, &a[i]);

}

for (j=0 ; j<(n-1) ; j++)

{

for (i=0 ; i<(n-1) ; i++)

{

if (a[i+1] < a[i])

{

t = a[i];

a[i] = a[i + 1];

a[i + 1] = t;

}

}

}

printf (“n Ascending order: “);

for (i=0 ; i<n ; i++)

{

printf (” %d”, a[i]);

}

printf (“n Descending order: “);

for (i=n ; i>0 ; i–)

{

printf (” %d”, a[i-1]);

}

/* indicate successful completion */

return 0;

}

/* OUTPUT:

Enter the no. of elements: 5

Enter the 1th element: 25

Enter the 2th element: 50

Enter the 3th element: 75

Enter the 4th element: 35

Enter the 5th element: 100

Ascending order: 25 35 50 75 100

Descending order: 100 75 50 35 25

Still stressed from student homework?
Get quality assistance from academic writers!