-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
65 lines (58 loc) · 1.07 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//============================================================================
// Name : quick.c
// Author : om purwar
// Version :
// Copyright : Your copyright notice
// Description : Quick Sort in C
//============================================================================
#include <stdio.h>
#include <conio.h>
int partition(int a[], int p, int r) {
int x = a[r];
int i = p - 1;
int j;
int temp;
for (j = p; j <= r - 1; ++j) {
if (a[j] <= x) {
++i;
int temp;
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
temp = a[i + 1];
a[i + 1] = a[r];
a[r] = temp;
return (i + 1);
}
void quicksort(int a[], int p, int r) {
if (p < r) {
int q;
q = partition(a, p, r);
quicksort(a, p, q - 1);
quicksort(a, q + 1, r);
}
}
void display(int a[]) {
int i;
printf("Displaying sorted array:\n");
for (i = 0; i < 10; ++i) {
printf("%d", a[i]);
printf("\n");
}
}
void fill(int a[]) {
int i;
for (i = 0; i < 10; ++i) {
scanf("%d", &a[i]);
}
}
int main() {
int a[10];
fill(a);
quicksort(a, 0, 9);
display(a);
getch();
return 0;
}