释延王少林八段锦下载:·C语言排序算法
来源:百度文库 编辑:九乡新闻网 时间:2024/05/04 07:15:59
1,冒泡排序:
#i nclude
#i nclude
using namespace std;
template
void swap(type x[],int,int);
template
void BubbleSort(type x[],int);
int main()
{
srand(time(0));
const int n=10;
int x[n];
for(int i=0;i x[ i]=rand()%99;
for(int i=0;i cout<<" "< BubbleSort(x,n);
cout<<"\nAfter Sort:"< for(int i=0;i cout<<" "<;
system("pause");
return 0;
}
template
void BubbleSort(type x[],int n)
{
for(int i=n-1;i>=0;i--)
{ int flag=0;
for(int j=0;j if(x[ j]>x[ j+1])
{ swap(x,j,j+1);
flag=1;
}
if(flag==0)
return;
}
}
template
void swap(type x[],int n,int m)
{ int temp=x[n];
x[n]=x[m];
x[m]=temp;
}
2,简单的选择排序
#i nclude
#i nclude
using namespace std;
template
void swap(type x[],int,int);
template
void SlectSort(type x[],int);
int main()
{
srand(time(0));
const int n=10;
int x[n];
for(int i=0;i x[ i]=rand()%99;
for(int i=0;i cout<<" "< SlectSort(x,n);
cout<<"\nAfter Sort:"< for(int i=0;i cout<<" "< system("pause");
return 0;
}
template
void swap(type x[],int n,int m)
{ int temp=x[n];
x[n]=x[m];
x[m]=temp;
}
template
void SlectSort(type x[],int n)
{
for(int i=0;i {
for(int j=i+1;j if(x[ j] swap(x,i,j);
}
}
3,插入排序
#i nclude
#i nclude
using namespace std;
template
void swap(type x[],int,int);
template
void InsertSort(type x[],int);
int main()
{
srand(time(0));
const int n=10;
int x[n];
for(int i=0;i
for(int i=0;i
cout<<"\nAfter Sort:"<
return 0;
}
template
void swap(type x[],int n,int m)
{ int temp=x[n];
x[n]=x[m];
x[m]=temp;
}
template
void InsertSort(type x[],int n)
{
for(int i=1;i
if(x[ j]
}
4:希尔排序
#i nclude
#i nclude
using namespace std;
template
void swap(type x[],int,int);
template
void ShellSort(type x[],int);
template
void ShellSorthelper(type x[],int,int);
int main()
{
srand(time(0));
const int n=10;
int x[n];
for(int i=0;i
for(int i=0;i
cout<<"\nAfter Sort:"<
return 0;
}
template
void swap(type x[],int n,int m)
{ int temp=x[n];
x[n]=x[m];
x[m]=temp;
}
template
void ShellSort(type x[],int n)
{
for(int i=n/2;i>=1;i/=2)
for(int j=0;j ShellSorthelper(&x[ j],i,n-j);
}
template
void ShellSorthelper(type x[],int len,int n)
{
for(int i=len;i
if(x[ j]
}
5,快速排序
#i nclude
#i nclude
using namespace std;
template
void QuicklySort(type x[],int n);
template
void QuicklySorthelper(type x[],int,int);
template
void swap(type x[],int,int);
int main()
{
srand(time(0));
const int n=10;
int x[ n];
for(int i=0;i
for(int i=0;i
cout<<"\nAfter Sort:"<
return 0;
}
template
void QuicklySort(type x[],int n)
{
QuicklySorthelper(x,0,n-1);
}
template
void QuicklySorthelper(type x[],int l,int r)
{ if(r>l)
{ swap(x,l,(l+r)/2);//尽量找出好的轴值;
int i=l;int j=r+1;type pivot=x[l];
while(i
while(x[--j]>pivot && i
while(x[++i]
}
x[ i]=pivot;
QuicklySorthelper(x,l,i-1);
QuicklySorthelper(x,i+1,r);
}
}
template
void swap(type x[],int n,int m)
{
type temp=x[n];
x[n]=x[m];
x[m]=temp;
}
6,归并排序(2路)
#i nclude
#i nclude
using namespace std;
template
void swap(type x[],int,int);
template
void MegicSort(type x[],int);
template
void MegicSorthelper(type x[],type y[],int,int);
template
void MegicSortPass(type x[],type y[],int,int,int);
int main()
{
srand(time(0));
const int n=10;
int x[n];
for(int i=0;i
for(int i=0;i
cout<<"\nAfter Sort:"<
return 0;
}
template
void swap(type x[],int m,int n)
{
type temp=x[m];
x[m]=x[n];
x[n]=temp;
}
template
void MegicSort(type x[],int n)
{ type *y=new type[n];
int len=1;
while(len
MegicSorthelper(x,y,len,n);len*=2;
MegicSorthelper(y,x,len,n);len*=2;
}
delete []y;
}
template
void MegicSorthelper(type x[],type y[],int len,int n)
{ int i;
for(i=0;i+2*len
if(i+len
else
for(;i
}
template
void MegicSortPass(type x[],type y[],int l,int m,int n)
{
int i=l,j=m,k=l;
for(;i
if(x[ i]>x[ j])
y[ k]=x[ j++];
else
y[ k]=x[ i++];
}
for(;i
for(;j
}
·C语言排序算法
[Python]python和C语言分别实现快速排序
嵌入式系统中FFT算法研究与实现(C语言)
快速排序算法说明
快速排序 算法分析
Java 冒泡排序算法
各种排序算法的比较
数据结构排序大全(C#)
11嵌入式系统中FFT算法研究与实现(C语言)
九之再续:教你一步一步用c语言实现sift算法、上
c语言
C语言
C语言
希尔排序基本思想、算法和示例
C 语言吧 · 问题资料大全
总结一些排序算法的原理和实现2
总结一些排序算法的原理和实现1
八种排序算法总结 - 舞亦香满衣 - CSDN博客
const用法详解 - C/C / C 语言
排序算法(Java实现): 插入,冒泡,选择,Shell,快速排序
排序算法复习(Java实现): 插入,冒泡,选择,Shell,快速排序
C语言经典教程
C语言系列教程
C语言谜题