0

Sorting

May I know how to make a function to sort the elements in ascending or descending order using selection sort and insertion sort

15th Mar 2021, 2:28 PM
Chelsea Feleca
Chelsea Feleca - avatar
4 Respostas
+ 1
Jayakrishna🇮🇳 Can you tell be how Insertion sort is different from Selection sort?
15th Mar 2021, 3:31 PM
Atul [Inactive]
15th Mar 2021, 2:31 PM
Jayakrishna 🇮🇳
0
Atul Once go through the link, you can understand it.. Selection Sort is first finds the smallest element in the array and swaps it with the element in the first 0th position, then finds the second and swaps it with second (1st) position, and continues for entire array.. Where as insertion sort, first arrange 1st 2 elements in order. Then next 3rd element is added in ascending order with 1,2. Now 1,2,3 are in ordered. Next 4th element is placed in order with 1,2,3,4 to its needed position.. so 1,2,3,4 is ordered now. This goes on for entire list. hope it helps..
16th Mar 2021, 9:52 AM
Jayakrishna 🇮🇳