File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 28
28
* [ Using max element] ( Sorting/SELECTION-SORT/selection.c )
29
29
* [ Using min element] ( Sorting/SELECTION-SORT/selectionsort.c )
30
30
* DESCENDING
31
- * [ Using max element] ( )
31
+ * [ Using max element] ( Sorting/SELECTION-SORT/maxselection.c )
32
32
* [ Using min element] ( )
33
33
34
34
### EXECUTION OF C CODE
Original file line number Diff line number Diff line change
1
+ //INSERTION SORT
2
+ //USING MAX ELEMENT
3
+ //DESCENDING
4
+ #include <stdio.h>
5
+ void selectionsort (int arr [],int n )
6
+ {
7
+ for (register int i = 0 ;i < n ;i ++ )
8
+ {
9
+ int max = i ;//max index
10
+ for (register int j = i ;j < n ;j ++ )
11
+ {
12
+ if (arr [max ]< arr [j ])
13
+ {
14
+ max = j ;
15
+ }
16
+ }
17
+ //swap
18
+ int temp = arr [i ];
19
+ arr [i ] = arr [max ];
20
+ arr [max ]= temp ;
21
+ }
22
+ }
23
+ int main ()
24
+ {
25
+ printf ("Enter the size of the array\n" );
26
+ int n ;
27
+ scanf ("%d" ,& n );
28
+ int arr [n ];
29
+ for (register int i = 0 ;i < n ;i ++ )
30
+ {
31
+ scanf ("%d" ,& arr [i ]);
32
+ }
33
+ selectionsort (arr ,n );
34
+ printf ("Sorted array:\n" );
35
+ for (register int i = 0 ;i < n ;i ++ )
36
+ {
37
+ printf ("%d " ,arr [i ]);
38
+ }
39
+ printf ("\n" );
40
+ }
You can’t perform that action at this time.
0 commit comments