File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+
3+ class InsertionSort
4+ {
5+ public static void main (String [] args )
6+ {
7+ int array []=new int [6 ];
8+ Scanner input =new Scanner (System .in );
9+
10+ //Input
11+ System .out .println ("Enter any 6 Numbers for Unsorted Array : " );
12+ for (int i =0 ; i <6 ; i ++)
13+ {
14+ array [i ]=input .nextInt ();
15+ }
16+
17+ //Sorting
18+ for (int i =0 ; i <6 ; i ++)
19+ {
20+ int temp =array [i ];
21+ int j =i -1 ;
22+ while (j >=0 && temp <array [j ] )
23+ {
24+ array [j +1 ]=array [j ];
25+ j --;
26+ }
27+
28+ array [j +1 ]=temp ;
29+ }
30+
31+ //Output
32+ for (int i =0 ; i <6 ; i ++)
33+ {
34+ System .out .print (array [i ]+"\t " );
35+ }
36+
37+ }
38+ }
Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+
3+ class SelectionSort
4+ {
5+ public static void main (String [] args )
6+ {
7+ int array []=new int [6 ];
8+ Scanner input =new Scanner (System .in );
9+
10+ //Input
11+ System .out .println ("Enter any 6 Numbers for Unsorted Array : " );
12+ for (int i =0 ; i <6 ; i ++)
13+ {
14+ array [i ]=input .nextInt ();
15+ }
16+
17+ //Sorting
18+ for (int i =0 ; i <6 ; i ++)
19+ {
20+ int min =i ;
21+ for (int j =i +1 ; j <6 ; j ++)
22+ {
23+ if (array [j ]<array [min ])
24+ {
25+ min =j ;
26+ }
27+ }
28+ int temp =array [i ];
29+ array [i ]=array [min ];
30+ array [min ]=temp ;
31+ }
32+
33+ //Output
34+ for (int i =0 ; i <6 ; i ++)
35+ {
36+ System .out .print (array [i ]+"\t " );
37+ }
38+
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments