//作者:Guo R.H
//日期:06.12.22
// USTC
#include
#include
#define N 50000
void selectsort(int a[])
{
//选择排序
int i, j, t, temp;
for(i=0; i {
temp = i;
for(j=i+1; j {
if(a[temp] > a[j])
temp=j;
}
if(temp != i)
{
t = a[temp];
a[temp] = a[i];
a[i] = t;
}
}
}
void bubblesort(int a[])
{
///冒泡排序
int t, i, j, temp;
t=1;
for(i=0; i {
t = 0;
for(j=i+1; j {
if(a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
t = 1;
}
}
}
}
void insertsort(int a[])
{
///插入排序
int i, j, temp;
for(i=1; i {
temp = a[i];
for(j=i-1; a[j]>temp && j>=0; j--)
a[j+1] = a[j];
a[j+1] = temp;
}
}
//快速排序
int partition(int a[], int low, int high)
{
int temp, p;
temp = low;
p = a[low];
while (low < high)
{
while(low=p)
high--;
if(low < high)
a[low++] = a[high];
while(low low++;
if(low < high)
a[high--] = a[low];
}
a[low] = p;
return low;
}
void quicksort(int a[], int s, int t)
{
//快速排序
int p;
if(s < t)
{
p=partition(a, s, t);
quicksort(a, s, p-1);
quicksort(a, p+1, t);
}
}
void shellsort(int a[], int n)
{
int h, j, i, t;
h = n/2;
while(h > 0)
{
for(j=h; j {
t = a[j];
for(i = j - h; i>=0 && a[i] > t; i -= h)
a[i+h] = a[i];
a[i+h] = t;
}
h /=2;
}
}
int main()
{
int i, j, temp, t, a[N];
for(i=0; i a[i] = rand()%100000;
shellsort(a,N);
for(i=0; i printf("%d ", a[i]);
}
阅读(819) | 评论(0) | 转发(0) |