Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "time.h"
- #include "random"
- #include "fstream"
- using namespace std;
- void qsort(int * a, int n){
- int c = a[rand()%n];
- int l=0;
- int r = n-1;
- do{
- while(a[l]<c) l++;
- while(a[r]>c) r--;
- if (l<=r){
- swap(a[l],a[r]);
- l++;
- r--;
- }
- }
- while (l<=r);
- if (l<n){
- qsort(a+l,n-l);
- }
- if (r>0){
- qsort(a,r+1);
- }
- }
- int main()
- {
- ofstream myfile;
- int n;
- cin>>n;
- int *a = new int[n];
- myfile.open ("example.txt");
- for (int k=0;k<10;k++){
- for (int x=0;x<n;x++){
- a[x]=rand()%1000;
- }
- int t1=clock();
- qsort(a,n);
- int t2=clock();
- myfile <<t2-t1<<"\n";
- }
- myfile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement