cosmin Administrator

Data inscrierii: 30/Apr/2010 Mesaje: 12
|
Trimis: 30/04/2010 09:25 Titlul subiectului: Quicsort |
|
|
#include<iostream>
using namespace std;
int mydarling_values[10]={8,0,3,1,5,6,2,9,7,4};
int n=10;
int my_pivot_action(int zone[],int from_here,int to_there)
{
int hit_me=0;
int i=from_here;
int j=to_there;
while(i<j)
{
if(zone[i]>zone[j])
{
int garbage;
garbage=zone[i];
zone[i]=zone[i+1];
zone[i+1]=garbage;
if(hit_me==0)
hit_me=1;
else
hit_me=0;
}
if(hit_me==0)
i++;
else
j--;
}
return i;
}
int my_quicksort(int zone[],int from_here,int to_there)
{
if(from_here<to_there)
{
int k;
k=my_pivot_action(zone,from_here,to_there);
my_quicksort(zone,from_here,k-1);
my_quicksort(zone,k+1,to_there);
}
return 0;
}
/*int print_data(int this_one[],int to_there)
{
for(int i=0;i<=mydarling_n-1;i++)
cout<<this_one[i]<<" ";
}
*/
int main()
{
int k;
for(int i=0;i<=n-1;i++)
cout<<mydarling_values[i]<<" ";
for(int i=0;i<=n-1;i++)
my_quicksort(mydarling_values,0,n-1);
cout<<endl<<endl;
for(int i=0;i<=n-1;i++)
cout<<mydarling_values[i]<<" ";
} |
|