File tree 3 files changed +80
-0
lines changed
3 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 21
21
* BUBBLE SORT
22
22
* [ ASCENDING AND STABLE] ( Sorting/BUBBLE-SORT/bubblesort.c )
23
23
* [ DESCENDING AND STABLE] ( Sorting/BUBBLE-SORT/bubble.c )
24
+ * [ ASCENDING AND UNSTABLE] ( Sorting/BUBBLE-SORT/ascendunbubble.c )
25
+ * [ DESCENDING AND UNSTABLE] ( Sorting/BUBBLE-SORT/descendunbubble.c )
24
26
25
27
### EXECUTION OF C CODE
26
28
Original file line number Diff line number Diff line change
1
+ //BUBBLE SORT
2
+ //ASCENDING ORDER
3
+ //UNSTABLE SORT
4
+ #include <stdio.h>
5
+ void bubblesort (int arr [],int n )
6
+ {
7
+ for (register int i = n - 1 ;i >=0 ;i -- )
8
+ {
9
+ for (register int j = 0 ;j < i ;j ++ )
10
+ {
11
+ if (arr [j ]>=arr [j + 1 ])
12
+ {
13
+ //swap
14
+ int temp = arr [j + 1 ];
15
+ arr [j + 1 ] = arr [j ];
16
+ arr [j ] = temp ;
17
+ }
18
+ }
19
+ }
20
+ }
21
+ int main ()
22
+ {
23
+ printf ("Enter the size of the array\n" );
24
+ int n ;
25
+ scanf ("%d" ,& n );
26
+ int arr [n ];
27
+ printf ("Enter the elements of the array\n" );
28
+ for (register int i = 0 ;i < n ;i ++ )
29
+ {
30
+ scanf ("%d" ,& arr [i ]);
31
+ }
32
+ bubblesort (arr ,n );
33
+ printf ("The sorted array:\n" );
34
+ for (register int i = 0 ;i < n ;i ++ )
35
+ {
36
+ printf ("%d " ,arr [i ]);
37
+ }
38
+ printf ("\n" );
39
+ }
Original file line number Diff line number Diff line change
1
+ //BUBBLE SORT
2
+ //DESCENDING ORDER
3
+ //UNSTABLE SORT
4
+ #include <stdio.h>
5
+ void bubblesort (int arr [],int n )
6
+ {
7
+ for (register int i = n - 1 ;i >=0 ;i -- )
8
+ {
9
+ for (register int j = 0 ;j < i ;j ++ )
10
+ {
11
+ if (arr [j ]<=arr [j + 1 ])
12
+ {
13
+ //swap
14
+ int temp = arr [j + 1 ];
15
+ arr [j + 1 ] = arr [j ];
16
+ arr [j ] = temp ;
17
+ }
18
+ }
19
+ }
20
+ }
21
+ int main ()
22
+ {
23
+ printf ("Enter the size of the array\n" );
24
+ int n ;
25
+ scanf ("%d" ,& n );
26
+ int arr [n ];
27
+ printf ("Enter the elements of the array\n" );
28
+ for (register int i = 0 ;i < n ;i ++ )
29
+ {
30
+ scanf ("%d" ,& arr [i ]);
31
+ }
32
+ bubblesort (arr ,n );
33
+ printf ("The sorted array:\n" );
34
+ for (register int i = 0 ;i < n ;i ++ )
35
+ {
36
+ printf ("%d " ,arr [i ]);
37
+ }
38
+ printf ("\n" );
39
+ }
You can’t perform that action at this time.
0 commit comments