#include "stdafx.h"
#include
#include
#include
void bubble(int a[], int size)
{
cout<<"?°?Y??Dò:"< for(int i = 1; i < size; i++)// loop size-1 times
{ for(int j = 0; j < size - i; j++)
if(a[j] > a[j+1])
{ int temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
for(int k = 0; k < size; k++)
cout< cout< }
}
void insert_sort(int a[], int size)
{
cout<<"2?è???Dò:"< int inserter,i = 0,index;
for(i = 1; i < size; i++)
{
inserter = a;
index = i - 1;
while(index >= 0 && inserter < a[index])//?-?·size-1′?
{ a[index+1] = a[index];
index--;
}
a[index+1] = inserter;//2?è?
for(int k = 0; k < size; k++)
{
cout< //if(k==i)
// cout<<"!";//?′??Dòμ?·??a??
}
cout< }
}
void quicksort(int a[], int low, int high)//?ì?ù??Dò
{
int i,j,key,temp;
for(i = 0; i <= high; i++)
cout<;
cout< if(low < high)
{
key = a[low];
i = low;
j = high;
while(i < j)
{
for( i = i + 1; i < high; i++)
if( a > key)
break;
for( j = j; j > low; j--)
if( a[j] < key)
break;
if(i < j)
{ temp = a;
a = a[j];
a[j] = temp;
}
}
temp = a[low];
a[low] = a[j];
a[j] = temp;
//cout<<"j:"< quicksort(a,low,j-1);
quicksort(a,i,high);
}
}
void shellsort(int a[], int low, int high)
{ cout<<"?£????Dò:"< int size = low + high + 1;
int d = size;
while(d > 1)
{ d = (d + 1)/2;//dè?5£?3£?2£?1
//cout<<"d:"< for(int i = low; i < size - d; i++)
if(a > a[i+d])
{ int temp = a;
a = a[i+d];
a[i+d] = temp;
}
for (int k = 0; k < size; k++)
cout< cout< }
}
void print(int s[],int size)
{ cout<<"Print:"< for(int j = 0; j < size; j++)
cout< cout<}
void select(int s[], int size)
{
int low = 0;
int high = size - 1;
int t;
cout<<"??????Dò·?·¨£o"< cout<<"1£o?°?Y??Dò"< cout<<"2£o2?è???Dò"< cout<<"3£o?ì?ù??Dò"< cout<<"4£o?£????Dò"< cout<<"0:í?3?"< cin>>t;
switch(t)
{ case 1: bubble(s,size); print(s,size);break;
case 2: insert_sort(s,size); print(s,size);break;
case 3: quicksort(s,low,high);print(s,size);break;
case 4: shellsort(s,low,high);print(s,size);break;
case 0: return;
default : cout<<"ê?è?′í?ó"< }
select(s,size);
}
int main(int argc, char* argv[])
{
int s[] = {2,4,6,5,1,3,9,7,0,8};
int size = sizeof(s)/sizeof(int);
select(s,size);
return 0;
}
0