|
Here is the program to sort the
given integer in ascending order using selection sort method.
Please find the
link to the pictorial tutor of the sorting. This program
needs to enter the length of the entering array, followed by
the array to be sorted.
The entered integers are stored
in the array A.
Logic :
Here, to sort the data in ascending order, the first element
A[0] is compared with all the other elements till the end of
the array. If it is greater than any other the elements then
they are interchanged. So after the first iteration of the
outer for loop smallest element will be placed at the
first position. The same procedure is repeated for the other
elements too.
If we complement the if
condition in this program, it will give out the sorted array
in descending order.
Sorting can also be done in other methods, like
bubble sorting and
insertion
sorting, which follows in the next pages.
|