注册 登录
编程论坛 C++教室

[求助]整数从小排到大的算法是什么(不用数组)

small_bike 发布于 2007-07-26 22:38, 687 次点击
输入几个正整数,输出从小到大的排列
6 回复
#2
aipb20072007-07-26 22:50

很多~冒泡,插入,选择,合并,快速,堆,希尔,哈希……

#3
small_bike2007-07-26 23:02

具体说一个

比如插入,和冒泡

#4
wtyj1122007-07-27 08:31

不用数组可以如果数据够多 就用堆 。不多就用链表。

#5
haihui2822007-07-27 09:39

#include<iostream>
#include<string>
using namespace std;

int main()
{
int a,b,c,d,e,f,temp=0;
int t[100];
cout << "please input the number of the data : ";
while(cin>>a)
{
for(f=0;f<100;f++)
t[f]=0;
for(b=0;b<a;b++)
cin >> t[b];
for(c=0;c<a;c++)
{
for(d=0;d<a-c;d++)
{
if(t[d]>t[d+1])
{
temp=t[d];
t[d]=t[d+1];
t[d+1]=temp;
}
}
}
cout << "the answer is : ";
for(e=1;e<=a;e++)
cout << t[e]<<" ";
cout << endl <<"pelase input the number of the next date : ";
}
return 0;
}

#6
medicihophy2007-07-30 13:10
用可变参数的函数实现不就可以了,其实有点狡辩,呵呵,因为底层上看都差不多!!
#7
fly8132007-07-30 13:36
可变参数的函数??不懂   
1