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
4 odpowiedzi
+ 1
Jayakrishna🇮🇳 Can you tell be how Insertion sort is different from Selection sort?
0
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..