没有合适的资源?快使用搜索试试~ 我知道了~
6中简单的排序算法分析
需积分: 4 2 下载量 169 浏览量
2008-12-18
00:19:02
上传
评论
收藏 5KB TXT 举报
温馨提示
试读
9页
6中排序算法结合(快速排序,冒泡排序,稀尔排序,堆排序,选择排序等)
资源推荐
资源详情
资源评论
#include<iostream.h>
#include<stdlib.h>
const int N=20;
int compcount;
int movecount;
void Beforesort()
{
compcount=0;
movecount=0;
}
void output(int table[],int n)
{
cout<<" table: ";
for(int i=0;i<n;i++)
cout<<table[i]<<" ";
cout<<endl;
}
void swap(int table[],int i, int j)
{
int temp=table[i];
table[i]=table[j];
table[j]=temp;
}
void print()
{
cout<<"compcount= "<<compcount<<endl;
#include<stdlib.h>
const int N=20;
int compcount;
int movecount;
void Beforesort()
{
compcount=0;
movecount=0;
}
void output(int table[],int n)
{
cout<<" table: ";
for(int i=0;i<n;i++)
cout<<table[i]<<" ";
cout<<endl;
}
void swap(int table[],int i, int j)
{
int temp=table[i];
table[i]=table[j];
table[j]=temp;
}
void print()
{
cout<<"compcount= "<<compcount<<endl;
cout<<"movecount= "<<movecount<<endl<<endl;
}
void insertsort(int table[],int n)
{
Beforesort();
cout<<"直接插入排序: \n";
for(int i=0;i<n;i++)
{
compcount++;
int m=table[i];
movecount=1;
int j=0;
while(j<i && m>=table[j])
j++;
cout<<"j="<<j ;
for(int h=i-1;h>=j;h--)
{
table[h+1]=table[h];
movecount+=3;
}
table[j]=m;
//movecount+=1;
cout<<"movecount"<<movecount;
output(table,n);
}
print();
}
}
void insertsort(int table[],int n)
{
Beforesort();
cout<<"直接插入排序: \n";
for(int i=0;i<n;i++)
{
compcount++;
int m=table[i];
movecount=1;
int j=0;
while(j<i && m>=table[j])
j++;
cout<<"j="<<j ;
for(int h=i-1;h>=j;h--)
{
table[h+1]=table[h];
movecount+=3;
}
table[j]=m;
//movecount+=1;
cout<<"movecount"<<movecount;
output(table,n);
}
print();
}
剩余8页未读,继续阅读
资源评论
cmk998108
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功