![]() |
VOOZH | about |
Sort an array in descending order means arranging the elements in such a way that the largest element at first place, second largest at second place and so on. In this article, we will learn different ways to sort an array in descending order in C.
The simplest method to sort the array in descending order is by using the in-built library function qsort(). Let's take a look at an example:
5 4 3 2 1
qsort() function uses quicksort algorithm and needs a comparator function for guiding it to sort the array in descending order.
C language only provides the built-in implementation of quick sort algorithm. If you want to use other sorting algorithm apart from quicksort, you have to manually implement it as shown:
Table of Content
Selection sort is a simple sorting algorithm that repeatedly finds the maximum element from the unsorted part of the array and places it at its position in the sorted part of the array until the complete array is sorted.
5 4 3 2 1
In Bubble Sort Algorithm, we repeatedly swap adjacent elements if they are in the wrong order. This process is repeated until the array is sorted in descending order.
5 4 3 2 1