标题:冒泡排序求解,运行时出错,为什么
取消只看楼主
nan1888
Rank: 2
等 级:论坛游民
帖 子:44
专家分:86
注 册:2011-6-19
结帖率:85.71%
已结贴  问题点数:20 回复次数:0 
冒泡排序求解,运行时出错,为什么
#include<iostream>
using namespace std;
#define max 10
struct node{
    int key;
}sqlist[max];
void doubledouble(struct node r[],int n)
{int i=0,j=n-1,b=1,l;
struct node t;
while(b)
{b=0;
for(l=j;l>i;i--)
if(r[l].key<r[l-1].key)
{
    b=1;

        t=r[l];
r[l]=r[l-1];
r[l-1]=t;}
i++;
for(l=i;l<j;l++)
if(r[l].key>r[l-1].key)
{b=1;
t=r[l-1];
r[l-1]=r[l];
r[l]=t;}
j--;
}
}

int main()
{int i,n,temp;
struct node r[10];
cout<<"输入元素个数"<<endl;
cin>>n;
for(i=0;i<n;i++)
{cin>>temp;
r[i].key=temp;
}
doubledouble(r,n);
for(i=0;i<n;i++)
cout<<r[i].key<<endl;
}

[ 本帖最后由 nan1888 于 2011-8-31 18:22 编辑 ]
搜索更多相关主题的帖子: include 元素 
2011-08-31 18:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-348817-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.742084 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved