-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquickSort.c
30 lines (24 loc) · 893 Bytes
/
quickSort.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
#include<stdio.h>
#include<time.h>
#include "integerSorting.h"
int main()
{
FILE *fin, *fout; // file pointers
int *a, n, i;
n=500; // number of elements
fin = fopen("To_Quick_Sort.txt","w+");
srand(time(NULL)); // used to generate distinct numbers at each execution of this program
for(i=0; i<n; ++i)
fprintf(fin," %d ",rand()%1000+1); // populate file with random numbers between 0 - 1000
rewind(fin); // take fin to the start of the file
a = allocateSpace(n); // function call to create space for an array
for(i=0;i<n;++i)
fscanf(fin,"%d",&a[i]); // store file content to the array
a = quickSort(a,0,n-1); // function call to perform Quick Sort
fout = fopen("Sorted_Using_Quick.txt","w+");
for(i=0; i<n; ++i)
fprintf(fout," %d ",a[i]); // populate file with sorted a[i] elements
fclose(fin);
fclose(fout);
return 0;
}