Skip to content

Commit e563c1f

Browse files
Update Sorting
1 parent cde725d commit e563c1f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Sorting

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,35 @@ public class Main
5858
System.out.print(Arrays.toString(a));
5959
}
6060
}
61+
// SELECTION SORT(NEITHER ADAPTIVE NOR STABLE)
62+
import java.util.*;
63+
public class Main
64+
{
65+
public static void main(String[] args) {
66+
Scanner sc = new Scanner(System.in);
67+
int n =sc.nextInt();
68+
int a[] = new int[n];
69+
for(int i=0;i<n;i++){
70+
a[i]=sc.nextInt();
71+
}
72+
selectionsort(a);
73+
74+
}public static void selectionsort(int arr[])
75+
{
76+
int n = arr.length;
77+
int minindex;
78+
for(int i=0;i<n-1;i++){
79+
minindex =i;
80+
for(int j=i+1;j<n;j++){
81+
if(arr[j]<arr[minindex]){
82+
minindex =j;
83+
}
84+
}
85+
int temp = arr[i];
86+
arr[i] = arr[minindex];
87+
arr[minindex] = temp;
88+
System.out.println("in "+ i+"swap"+Arrays.toString(arr));
89+
}
90+
return ;
91+
}
92+
}

0 commit comments

Comments
 (0)