-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPartition.c
50 lines (39 loc) · 1002 Bytes
/
Partition.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
// partition.c
#include <stdio.h>
#define N 20
void printArray(int [], int);
void partition(int[],int,int);
int main(void) {
int size,i,pivot,array[N];
printf("Enter the number of elements: ");
scanf("%d", &size);
printf("Enter %d integers: ", size);
for(i = 0; i < size; i++){
scanf("%d", &array[i]);
}
printf("Enter pivot: ");
scanf("%d", &pivot);
partition(array,size,pivot);
// printf("rubbish");
printArray(array,size);
return 0;
}
// Print array arr
void printArray(int arr[], int size) {
int i;
// printf("rubbish");
for (i=0; i<size; i++)
printf("%d ", arr[i]);
printf("\n");
}
void partition(int array[],int size,int pivot){
int i,sIndex = 0,temp;
for(i = 0; i < size; i++){
if(array[i] < pivot){
temp = array[i];
array[i] = array[sIndex];
array[sIndex] = temp;
sIndex ++; //end of small number
}
}
}