From c7caca7f9e7c15b9935c99add57ddbe3fe597eb5 Mon Sep 17 00:00:00 2001 From: NEHA-MERIYA <93333850+NEHA-MERIYA@users.noreply.github.com> Date: Sun, 31 Oct 2021 22:10:09 +0530 Subject: [PATCH] Create SelectionSort10 This program is written in java language. It inputs 10 integers from user ,performs selection sort on the integers and prints in ascending order. The program has been executed and it works fine. Please review and approve my PR for HACKTOBERFEST2021 with label hacktoberfest-accepted. Thank you :) --- SelectionSort10 | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 SelectionSort10 diff --git a/SelectionSort10 b/SelectionSort10 new file mode 100644 index 0000000..1db46bd --- /dev/null +++ b/SelectionSort10 @@ -0,0 +1,41 @@ +import java.io.*; + +public class SelectionSort10 { + public static void selsort(int A[]) { + int i, j, small, tmp, pos; + for (i = 0; i < 10; i++) { + small = A[i]; + pos = i; + for (j = i + 1; j < 10; j++) { + if (A[j] < small) { + small = A[j]; + pos = j; + } + } + tmp = A[i]; + A[i] = A[pos]; + A[pos] = tmp; + } + System.out.println("Array in ascending order="); + for (i = 0; i < 10; i++) + System.out.println(A[i]); + } + + public static void main(String[] args) { + int A[] = new int[10]; + BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); + String inStr = null; + System.out.println("Enter 10 elements of array="); + try { + for (int i = 0; i < 10; i++) { + inStr = buf.readLine(); + A[i] = Integer.parseInt(inStr); + } + } catch (Exception e) { + System.out.println("Error in data entry"); + System.out.println("Exception=" + e); + return; + } + selsort(A); + } +}