Monday, 10 March 2014

Program In C++ for quicksort sort and its time complexity

#include<iostream.h>
#include<conio.h>
#include<time.h>
#include<dos.h>
int Partition(int a[],int p,int r)
{ int tmp,x=a[r];
int i=p-1;
for(int j=p;j<r;j++)
if(a[j]<x)
{ i++;
tmp=a[i];
a[i]=a[j];
a[j]=tmp; }
tmp=a[i+1];
a[i+1]=a[r];
a[r]=tmp;
return i+1; }
void quicksort(int a[],int p,int r)
{ int q;
if(p<r)
 { q=Partition(a,p,r);
quicksort(a,p,q-1);
quicksort(a,q+1,r); }}

int main()
{ clrscr();
int a[10],n,i,j,tmp;
clock_t start,end;
cout<<"Enter Array Size: ";
cin>>n;
cout<<"\nEnter Array: ";
for(i=0;i<n;i++)
{ cin>>a[i]; }
start=clock();
quicksort(a,0,n-1);
delay(100);
end=clock();
cout<<"\nArray After Sorting Is: ";
for(i=0;i<n;i++)
{ cout<<a[i]<<"\t"; }
cout<<"\nTime Taken Is: "<<(end-start)/CLK_TCK<<" seconds";
getch();
return 0;
}

1 comment:

  1. PlayOJO Casino: 10 Free Spins No Deposit Bonus Codes
    PlayOJO Casino gives 목포 출장마사지 you a 밀양 출장샵 unique 영천 출장샵 bonus code which you can 부천 출장마사지 use with its casino games. Get 10 free spins no deposit on registration to play at 안동 출장마사지 the best

    ReplyDelete