-
Notifications
You must be signed in to change notification settings - Fork 0
/
quick_sort.c
70 lines (54 loc) · 1.32 KB
/
quick_sort.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
66
67
68
69
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <stdbool.h>
#define MAX_ELEMENTS 2
#define MAX_NUMBER_LENGTH 50
void sort(int *array, int array_size);
int main()
{
int iterator = 0;
//int array[MAX_ELEMENTS] = {9, 4, 6, 3, 2, 1, 0, 8, 7, 5};
int array[MAX_ELEMENTS] = {2, 5};
#ifdef INPUT
char number[MAX_NUMBER_LENGTH];
printf("insert %d elements into the array:\n", MAX_ELEMENTS);
for(iterator=0; iterator < MAX_ELEMENTS; iterator++)
{
fgets(number, sizeof(number), stdin);
array[iterator] = atoi(number);
}
printf("entered array is:\n");
for(iterator=0; iterator < MAX_ELEMENTS; iterator++)
{
printf("%d: %d\n",iterator, array[iterator]);
}
#endif
sort(array, sizeof(array)/sizeof(int));
printf("sorted array is:\n");
for(iterator=0; iterator < MAX_ELEMENTS; iterator++)
{
printf("%d: %d\n",iterator, array[iterator]);
}
return 1;
}
void sort(int *array, int array_size)
{
if (array_size <= 1)
{
return
}
int pivot = array[array_size/2];
}
void swap(int *array, int position1, int position2)
{
int temp;
if (position1 == position2)
{
return;
}
temp = array[position1];
array[position1]=array;
array[position2]=temp;
}