游客已登陆 (0)未知
笔行证 257310
昵称 kuan 
笔贝 Score1
加为好友 发送短信
<< << 2009 一月 >> >>
123
45678910
11121314151617
18192021222324
25262728293031

访问计数:27089
本文:260 今天:1 本月 260

本地音乐播放器



 
       直接插入排序
2007-04-12 晴



#include<iostream.h>

void InsertSort(float array[], int n)//稳定 时间O(n^2)
{
int i,j;
float temp;
for(i=1; i<n; i++)
{
temp=array;//备份
for(j=i-1; j>=0; j--)//在排好序的数组里,从后往前
if(temp<array[j])
array[j+1]=array[j];
else
break;
array[j+1]=temp;
}
}

void main()
{
int i,n;
cout<<"你输入几个数进行排序:";
cin>>n;
float *array=new float[n+1];
cout<<"请输入"<<n<<"个数:"; //36 25 48 12 65 43 20 58
for(i=0; i<n; i++)
cin>>array;

InsertSort(array,n);

cout<<"排好序的数:";
for(i=0; i<n; i++)
cout<<array<<' ';
cout<<endl;
delete []array;
array=NULL;
}.
# posted by kuan @ 2007-04-12 12:53:15 评论(0)
 








 
笔 名:
*
评 论:
最多1000字。当前字数:0
*
联系方式: