-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsortquik.c
41 lines (39 loc) · 962 Bytes
/
sortquik.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
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void quicksort (int a[], int low, int high){
int x, y, p, temp ;
x = low ;
y = high ;
p = a[(x+y)/2] ;
do{
while (a[x] < p) x++ ;
while (a[y] > p) y-- ;
if (x <= y){
temp = a[x] ;
a[x] = a[y] ;
a[y] = temp ;
x++ ;
y-- ;
}
}while (x <= y) ;
if (low < y) quicksort (a, low, y) ;
if (x < high) quicksort (a, x, high) ;
}
int main(){
int a[20], size;
printf("----------Akash Shukla------------\n");
printf("Enter the array size: ");
scanf("%d", &size);
printf("Enter the array elements: ");
for (int i = 0; i < size; i++){
scanf("%d", &a[i]);
}
quicksort(a, 0, size-1);
printf("Sorted array is: ");
for (int i = 0; i < size; i++){
printf("%d ", a[i]);
}
getch();
return 0;
}