How do you sort an array in decreasing order?
Answer / Ritesh Kumar Jaiswal
You can perform any sorting algorithm and modify it slightly to sort an array in decreasing order. For example, for bubble sort:
1. Initialize the array as unsorted.
2. For each step i from 0 to len(array)-1:
a. For j from 0 to len(array)-i-1:
i) If array[j] > array[j+1]: swap array[j] and array[j+1].
The above pseudocode is similar to bubble sort, but it compares the larger value first before swapping. This ensures that the sorted array will be in decreasing order.
| Is This Answer Correct ? | 0 Yes | 0 No |
What is a matrix?
Why merge sort is better than insertion sort?
What is worst case complexity algorithm?
Which type of sorting is best?
Why it is important to have aligned addresses? What is the exception generated when there is a misaligned address?
What does abstract data type means?
23 Answers College School Exams Tests, Infosys, SBIT, TCS,
How many types of searching are there in data structure?
How to reverse singly link list?
What are the tasks performed while traversing a binary tree?
What is sorting problem?
How can we reverse the order in the treemap?
How would you sort a linked list?