Created
October 28, 2025 15:50
-
-
Save mustafadalga/a878104bcf50b99af94703948044d3f1 to your computer and use it in GitHub Desktop.
Selection sort is a sorting algorithm that repeatedly scans an unsorted array and with each iteration finds the minimum element to build up a sorted array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function selectionSort(arr) { | |
| for(let i=0;i<arr.length;i++){ | |
| for(let j=i+1;j<arr.length;j++){ | |
| if(arr[i]>arr[j]){ | |
| const temp=arr[i] | |
| arr[i]=arr[j] | |
| arr[j]=temp | |
| } | |
| } | |
| } | |
| return arr | |
| } | |
| selectionSort([9, 3, 6, 2, 1, 11]); // [1, 2, 3, 6, 9, 11] | |
| selectionSort([12, 16, 14, 1, 2, 3]); // [1, 2, 3, 12, 14, 16] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment