File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ // BUBBLE SORT
3
+
4
+ #include <stdio.h>
5
+
6
+
7
+ void bubblesort (int arr [], int size )
8
+ {
9
+ int i , j ;
10
+ for (i = 0 ; i < size ; i ++ ) // Function where the actual algorithm is implemented
11
+ {
12
+ for (j = 0 ; j < size - i ; j ++ )
13
+ {
14
+ if (arr [j ] > arr [j + 1 ])
15
+ swap (& arr [j ], & arr [j + 1 ]);
16
+
17
+ }
18
+ }
19
+ }
20
+ void swap (int * a , int * b )
21
+ {
22
+ int temp ; // Function for swapping two variables
23
+ temp = * a ;
24
+ * a = * b ;
25
+ * b = temp ;
26
+ }
27
+ int main ()
28
+ {
29
+ int array [100 ], i , size ;
30
+ printf ("How many numbers you want to sort: " ); // Enter the numbers to sort
31
+
32
+ scanf ("%d" , & size );
33
+
34
+ printf ("\nEnter %d numbers : " , size );
35
+ for (i = 0 ; i < size ; i ++ )
36
+ scanf ("%d" , & array [i ]);
37
+ bubblesort (array , size );
38
+ printf ("\nSorted array is " );
39
+
40
+ for (i = 0 ; i < size ; i ++ )
41
+ printf (" %d " , array [i ]);
42
+ return 0 ;
43
+
44
+ }
You can’t perform that action at this time.
0 commit comments