File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed
Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change 1+ #include <stdio.h>
2+ #include <stdlib.h>
3+ #include <time.h>
4+
5+ void display (int arr [], int size )
6+ {
7+ for (int i = 0 ; i < size ; i ++ )
8+ {
9+ printf ("%d " , arr [i ]);
10+ }
11+
12+ printf ("\n" );
13+ }
14+
15+ void swap (int * num1 , int * num2 )
16+ {
17+ int temp = * num1 ;
18+ * num1 = * num2 ;
19+ * num2 = * num1 ;
20+ }
21+
22+ void slowsort (int arr [], int low , int high )
23+ {
24+ if (low >= high )
25+ return ;
26+
27+ int middle = (low + high ) / 2 ;
28+
29+ slowsort (arr , low , middle );
30+ slowsort (arr , middle + 1 , high );
31+
32+ if (arr [high ] < arr [middle ])
33+ swap (& arr [high ], & arr [middle ]);
34+
35+ slowsort (arr , low , high - 1 );
36+ }
37+
38+ void test ()
39+ {
40+ const int size = 20 ;
41+
42+ int * arr = (int * )calloc (size , sizeof (int ));
43+
44+ for (int i = 0 ; i < size ; i ++ )
45+ {
46+ arr [i ] = rand () % 100 ;
47+ }
48+
49+ slowsort (arr , 0 , size - 1 );
50+
51+ display (arr , size );
52+
53+ free (arr );
54+ }
55+
56+ int main ()
57+ {
58+ srand (time (NULL ));
59+ test ();
60+ return 0 ;
61+ }
You can’t perform that action at this time.
0 commit comments