正文

c++(冒泡排序)2005-09-21 23:48:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/wojiele/5085.html

分享到:

#include<iostream>#define swap(x,y,t)((t)=(x),(x)=(y),(y)=(t))using namespace std;const int N=10;void sort(int b[],int count);int main(){    int a[N];    cout<<endl        <<"please input the "<<N<<"numbers:"<<endl;    for(int i=0;i<N;i++)        cin>>a[i];    cout<<endl        <<"the original numbers you have inputed are: "<<endl;    for(i=0;i<N;i++)    cout<<" "<<a[i];    cout<<endl        <<"After sorting the numbers ,the numbers are:"<<endl;    sort(a,N);    return 0;}void sort(int b[],int count){    int t,tempt;    for(int i=0;i<count;i++)    {    t=count-i-1;    for(int j=0;j<t;j++)    {        if(b[j]>b[j+1])            swap(b[j],b[j+1],tempt);    }    }    for(i=0;i<N;i++)        cout<<" "<<b[i];}

阅读(8621) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册