forked from govind2006/codes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filequicksort.c
50 lines (45 loc) · 866 Bytes
/
filequicksort.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
#include<stdio.h>
void quicksort(int a[ ],int p,int q){
int i, j, v, temp;
if(q>p){
v=p;
i=p;
j=q;
while(i<j){
while(a[i]<=a[v]&&i<q)
i++;
while(a[j]>a[v] && j>p)
j--;
if(i<j){
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
temp=a[v];
a[v]=a[j];
a[j]=temp;
quicksort(a,p,j-1);
quicksort(a,j+1,q);
}
}
int main()
{
int i,n;
FILE *f;
printf("enter the size of array=");
scanf("%d",&n);
int a[n];
f = fopen("C.txt","w");
for (i = 0; i <n; i++)
fprintf(f,"%d\n",rand() % n +1);
fclose(f);
f= fopen("C.txt","r");
for(i=0;i<n;i++)
fscanf(f,"%d\n", &a[i]);
fclose(f);
quicksort(a,0,n-1);
printf("sorted array=");
for(i=0;i<n;i++)
printf(" %d\t",a[i]);
}