分类: C/C++
2010-08-14 15:58:56
插入排序
void InsertSort(int *p,int len)
{
int i;
int j;
int tmp;
for(i=1;i
if(a[i-1]>a[i])
{
tmp=a[i];
a[i]=a[i-1];
for(j=i-2;(j!=-1)&&a[j]>tmp;j--)
a[j+1]=a[j];
a[j+1]=tmp;
}
}
}
希尔排序
int dt[]={3,2,1};
void shellsort(int *p,int d,int len)
{
int i;
int tmp;
int j;
for(i=d;i
if(p[i-d]>p[i])
{
tmp=p[i];
p[i]=p[i-d];
for(j=(i-2*d);(j>=0)&&p[j]>tmp;j-=d)
p[j+d]=p[j];
p[j+d]=tmp;
}
}
}
快速排序
void QuickSort(int *p,int low,int high)
{
int pivc;
if(low
pivc=Partition(p,low,high);
QuickSort(p,low,pivc-1);
QuickSort(p,pivc+1,high);
}
}
int Partition(int *p,int low,int high)
{
int tmp=p[low];
while(low
while((low
p[low]=p[high];
while((low
}
p[low]=tmp;
return low;
}