linxuex

C++学习者

常用链接

统计

最新评论

2007年4月21日 #

请 教

编一个程序,用同一个函数名对n个数据进行从小到大排序,数据类型可以是整型,单精度型,双精度型。用重载函数实现
#include<iostream>
#include<string>
using namespace std;
int main()
{ long a[5]={10100, -123567, 1198783, -165654, 3456};
  int b[5]={1,9,0,23,-45};
  float c[5]={2.4,7.6,5.5,6.6,-2.3};
  void sort(long []);
  void sort(int []);
  void sort(float []);
  sort(a);
  sort(b);
  sort(c);
  return 0;
}

void sort(long [])
{int i,j;
 long t;
 for(j=0;j<5;j++)
   for(i=0;i<5-j;;j++)
    if(a[i]>a[i+1])
    {t=a[i];a[i]=a[i+1];a[i+1]=t;}
 cout<<"the sorted numbers:"<<endl;
 for(i=0;i<5;j++)
  cout<<a[i]<<" ";
 cout<<endl<<endl;
}

void sort(int [])
{int i,j,t;
 for(j=0;j<5;j++)
   for(i=0;i<5-j;;j++)
    if(a[i]>a[i+1])
    {t=a[i];a[i]=a[i+1];a[i+1]=t;}
 cout<<"the sorted numbers:"<<endl;
 for(i=0;i<5;j++)
  cout<<a[i]<<" ";
 cout<<endl<<endl;
}

void sort(float [])
{int i,j;
 float t;
 for(j=0;j<5;j++)
   for(i=0;i<5-j;;j++)
    if(a[i]>a[i+1])
    {t=a[i];a[i]=a[i+1];a[i+1]=t;}
 cout<<"the sorted numbers:"<<endl;
 for(i=0;i<5;j++)
  cout<<a[i]<<" ";
 cout<<endl<<endl;
}

 
 //d:\c++6.0\vs63in1 (g)\vc60chs\vc98\include\ios(9) : fatal error C1083: Cannot open include file: 'streambuf.h': No such file or directory
Cpp1.obj - 1 error(s), 0 warning(s)  请问是什么原因?如何解决?
                                                                                                                    C++初学习者

posted @ 2007-04-21 09:14 linxuex 阅读(849) | 评论 (13)编辑 收藏

仅列出标题