How do you sort an array in decreasing order?



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

Post New Answer

More Data Structures Interview Questions

What is a matrix?

1 Answers  


Why merge sort is better than insertion sort?

1 Answers  


What is worst case complexity algorithm?

1 Answers  


Which type of sorting is best?

1 Answers  


Why it is important to have aligned addresses? What is the exception generated when there is a misaligned address?

1 Answers   Ciena,


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?

1 Answers  


How to reverse singly link list?

1 Answers  


What are the tasks performed while traversing a binary tree?

1 Answers  


What is sorting problem?

1 Answers  


How can we reverse the order in the treemap?

1 Answers  


How would you sort a linked list?

5 Answers  


Categories