From fb08cae9319afaf106d89fb3a6b1b28207acb68f Mon Sep 17 00:00:00 2001 From: Vishal Kumar Singh Date: Sat, 24 Oct 2020 14:25:11 +0530 Subject: [PATCH] Aesthetic --- SelectionSortPedro.java | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/SelectionSortPedro.java b/SelectionSortPedro.java index 185e9ab..fdca74c 100644 --- a/SelectionSortPedro.java +++ b/SelectionSortPedro.java @@ -1,10 +1,14 @@ -public class SelectionSortPedro { - public static void selectionSort(int[] arr){ +public class SelectionSortPedro +{ + public static void selectionSort(int[] arr) + { for (int i = 0; i < arr.length - 1; i++) { int index = i; - for (int j = i + 1; j < arr.length; j++){ - if (arr[j] < arr[index]){ + for (int j = i + 1; j < arr.length; j++) + { + if (arr[j] < arr[index]) + { index = j;//searching for lowest index } } @@ -14,19 +18,20 @@ public static void selectionSort(int[] arr){ } } - public static void main(String a[]){ + public static void main(String a[]) + { int[] arr1 = {9,14,3,2,43,11,58,22}; System.out.println("Before Selection Sort"); - for(int i:arr1){ + for(int i:arr1) System.out.print(i+" "); - } + System.out.println(); selectionSort(arr1); System.out.println("After Selection Sort"); - for(int i:arr1){ + for(int i:arr1) System.out.print(i+" "); - } + } } \ No newline at end of file