这个冒泡程序怎么没有调用,哪里有问题?可以编译!

wangliuqing 2009-05-16 12:47:44
#include<iostream>
using namespace std;

void maopao(int list[],int n);
void maopao(int list[],int n)
{
int exchange,i,j,temp;
for(int i=1;i<n;i++)
exchange=0;
for(int j=n-1;j>i;j--)
if(list[j+1]<list[j])
temp=list[j+1];
list[j+1]=list[j];
list[j]=list[j+1];
exchange=1;
}
// if(exchange=1)
// return ;

int main()
{ const char blank=' ';
const int n=10;
int list[n]={1,3,5,7,9,2,4,6,10,0};
void maopao(int list[],int n);
for(int i=0;i<n;i++)
{
cout<<list[i]<<blank;
if((i+1)%10==0) cout<<endl;
}
cout<<endl;
system("pause");
return 0;
}
...全文
126 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangliuqing 2009-05-19
  • 打赏
  • 举报
回复
if(exchange==1)
return ;
并入到函数里面去了就可以了!\

wangliuqing 2009-05-17
  • 打赏
  • 举报
回复
各位楼主说得是,C++有些东西没弄清楚啊!但把
// if(exchange=1)
// return ;
这个加上效率会高一些,但加上后提示的错误,不知道什么原因!
coverallwangp 2009-05-16
  • 打赏
  • 举报
回复
void maopao(int list[],int n);这是声明不是调用

改成:maopao(list,n);
ahui5252 2009-05-16
  • 打赏
  • 举报
回复
void maopao(int list[], int n);去掉()里面的两个int ;
Jalien 2009-05-16
  • 打赏
  • 举报
回复
void maopao(int list[],int n);
呵呵,这个是声明啊,调用要去掉void
dinghdong 2009-05-16
  • 打赏
  • 举报
回复
lz的基础还是要加强啊!希望早日成为高手!
T技术沙龙 2009-05-16
  • 打赏
  • 举报
回复
#include<stdio.h>
void paixu(char str[10])
{
int i,j,t;
for(j=0;j<10;j++)
for(i=0;i<9-j;i++)
if(str[i]>str[i+1])
{
t=str[i];
str[i]=str[i+1];
str[i+1]=t;
}
}
void main()
{
char str[10];
int i;
gets(str);
paixu(str);
for(i=0;i<10;i++)
printf("%c",str[i]);
printf("\n");
}

以前写的c语言的,楼主看看吧,重点还是一样的
lingyin55 2009-05-16
  • 打赏
  • 举报
回复


//改了个。
#include <iostream>
using namespace std;

void maopao(int list[],int n);
void maopao(int list[],int n)
{
int exchange,i,j,temp;
for(int i=0;i <n;i++)
{
exchange=0;
for(int j=0;j<n-i;j++) ///////////
//{
if(list[j+1] <list[j])
{
temp=list[j];
list[j]=list[j+1];
list[j+1]=temp;
exchange=1;
}
//}
}
}
// if(exchange=1)
// return ;

int main()
{ const char blank=' ';
const int n=10;
int list[n]={1,3,5,7,9,2,4,6,10,0};
maopao(list,10);
for(int i=0;i <n;i++)
{
cout <<list[i] <<blank;
if((i+1)%10==0) cout <<endl;
}
cout <<endl;
system("pause");
return 0;
}
majun01 2009-05-16
  • 打赏
  • 举报
回复
#include <iostream> 
using namespace std;

void maopao(int list[],int n)
{
int exchange,i,j,temp;
for(i=0;i <n;i++) //////////改
{ //////////改
exchange=0;
for(j=n-1;j>i;j--) //////////改
{
if(list[j] <list[j-1]) //////////改
{
temp=list[j-1];
list[j-1]=list[j];
list[j]=temp; //////////改
exchange=1;
}
}
}
}
// if(exchange=1)
// return ;

int main()
{ const char blank=' ';
const int n=10;
int list[n]={1,3,5,7,9,2,4,6,10,0};
maopao(list,n); //////////改
for(int i=0;i <n;i++)
{
cout<<list[i]<<blank;
if((i+1)%10==0) cout<<endl;
}
cout<<endl;
system("pause");
return 0;
}

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧