{"id":18020716,"url":"https://github.com/inforkgodara/selection-sort","last_synced_at":"2025-04-04T17:16:46.086Z","repository":{"id":110250336,"uuid":"233583044","full_name":"inforkgodara/selection-sort","owner":"inforkgodara","description":"A single class implementation of selection sort","archived":false,"fork":false,"pushed_at":"2020-08-02T11:23:36.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-10T02:38:51.433Z","etag":null,"topics":["data-structures","inforkgodara","java","selection-sort"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/inforkgodara.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-13T11:45:28.000Z","updated_at":"2020-08-03T13:48:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"b13830a1-79c3-46e0-86b6-0c04c5069c36","html_url":"https://github.com/inforkgodara/selection-sort","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inforkgodara%2Fselection-sort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inforkgodara%2Fselection-sort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inforkgodara%2Fselection-sort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inforkgodara%2Fselection-sort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inforkgodara","download_url":"https://codeload.github.com/inforkgodara/selection-sort/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247217220,"owners_count":20903009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-structures","inforkgodara","java","selection-sort"],"created_at":"2024-10-30T06:07:24.692Z","updated_at":"2025-04-04T17:16:46.066Z","avatar_url":"https://github.com/inforkgodara.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Selection Sort\n\nA simple single class implementation of selection sort in Java. The user will be prompted to input the number of elements in a list array which they want to enter. The list array is divided into two parts, the sorted part at the left end and the unsorted part at the right end. Initially, the sorted part is empty and the unsorted part is the entire list.\n\nThe smallest element is selected from the unsorted array and swapped with the leftmost element, and that element becomes a part of the sorted array. This process continues moving unsorted array boundaries from one element to the right.\n\n## How to use it.\n* Open a command prompt window and go to the directory where you saved the java program (SelectionSort.java).\n* Type 'javac SelectionSort.java' and press enter to compile your code. If there are no errors in your code, the command prompt will take you to the next line.\n* Now, type 'java SelectionSort' to run your program.\n* You will be able to see an output line and asking input to enter the number of elements (integer) you want to enter.\n* Next you will enter the number of elements it can be space-separated or in a new line.\n* After completion of entering elements in list, the program will show sorted list.\n\n## Code\n```\nimport java.util.Scanner;\n\n/**\n * This is an implementation of the selection sort algorithm.\n * @author @inforkgodara\n *\n */\npublic class SelectionSort {\n\n    /**\n     * Selection sort implementation.\n     * @param list the array to be sorted.\n     * @param length the integer which size of list.\n     */\n    static void sort(int list[], int length) { \n        for (int i = 0; i \u003c length-1; i++) \n        { \n            int minIndex = i; \n            for (int j = i+1; j \u003c length; j++) {\n                if (list[j] \u003c list[minIndex]) {\n                    minIndex = j;\n                }\n            }\n            int temp = list[minIndex];\n            list[minIndex] = list[i]; \n            list[i] = temp; \n        } \n    }\n\n    public static void main(String[] args) {\n        System.out.print(\"Enter length of list : \");\n        Scanner scanner = new Scanner(System.in);\n\n        int length = scanner.nextInt();\n        int[] list = new int[length];\n\n        for (int index = 0; index \u003c length; index++) {\n            list[index] = scanner.nextInt();\n        }\n\n        sort(list, length);\n\n        System.out.print(\"Sorted list: \");\n\n        for (int element: list) {\n            System.out.print(element + \" \");\n        }\n    }\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finforkgodara%2Fselection-sort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finforkgodara%2Fselection-sort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finforkgodara%2Fselection-sort/lists"}