求一个二维字符型数组的排序,为什么不对啊!用冒泡法对数组!新手

习题五--数组_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
习题五--数组
上传于||暂无简介
阅读已结束,如果下载本文需要使用0下载券
想免费下载更多文档?
定制HR最喜欢的简历
下载文档到电脑,查找使用更方便
还剩1页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢a是长度为10的整型数组 编程对其奇下标位置排序 偶下标位置值不变 排序方法用冒泡排序 要求排序功能用函数_百度知道
a是长度为10的整型数组 编程对其奇下标位置排序 偶下标位置值不变 排序方法用冒泡排序 要求排序功能用函数
提问者采纳
并赋给b[i]for(int i =0;5;/i&j&//将b中的值返还给a中相应的元素for(int i =0,j; x[j+1] ){tmp=x[j];i++){b[i]=a[2*i+1];for(i=0;/long b[5];冒泡排序功能函数;j++){if( x[j] &}function(b);/i&5;x[j]=x[j+1];i++){for(j=0;5;&#47,采用升序排序function(long[] x){}}/i&i++){a[2*i+1]=b[i];提取a中奇下标位的数;对b数组进行冒泡排序&#47main(){long a[10] = {你需要的十个数};4-i;x[j+1]=tmp
提问者评价
太感谢了,真心有用
来自团队:
其他类似问题
为您推荐:
冒泡排序的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁求一个二维字符型数组的排序,为什么不对啊!用冒泡法!新手_百度知道
求一个二维字符型数组的排序,为什么不对啊!用冒泡法!新手
%c &i&j++)
printf(&quot,&&#92.h&j&j&;
printf(&3;
for(i=0;2,j#include &a[i][j+1])
c=a[i][j],&a[i][j]);j&lt,i;j++)
if (a[i][j]&i++) for(j=0,a[i][j]);m++)
for(j=0;m&%c;i&
a[i][j]=a[i][j+1];);;j++)
scanf(&2-m;3;i++)
for(j=0,m;i&n&3;i++)
for(m=0; for(i=0;3;void main(){ int a[3][3];3;
a[i][j+1]=c
我有更好的答案
or(m=0;2;m++ 循环这里有错误
是3 吧 2的话就是第一个 跟第二个 两个数的比较啊 这样也行 for(m=0;m&=2;m&lt
数据的 输入有错你定义的为
int 型,输入时就应该是 %d
表示字符型程序中两个地方要修改为scanf(&%d&,&a[i][j]);printf(&%d\t&,a[i][j]);--参考一下吧
其他类似问题
为您推荐:
冒泡法的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁用冒泡排序法将一个n行m列的二维数组的每一行按从大到小的顺序排序.要求二维数组的输入排序和输出分别用一_百度知道
用冒泡排序法将一个n行m列的二维数组的每一行按从大到小的顺序排序.要求二维数组的输入排序和输出分别用一
要求二维数组的输入排序和输出分别用一个函数实现.组的行数和列数在主函数中实现
提问者采纳
&输出排序之后的数;&i&&int&&main(){&&&printf(&quot,i;&&&&&nbsp,a[i][j]).hiphotos,m;m;&n;&x++)&&&&&&%5d&%d&quot://g;a[i][j]);&&&nbsp,x;j++)&&for(i=0;;a[i][j+1])&&&.com/zhidao/pic/item/960a304e251f95cacf453dcac9521d;printf(&&nbsp,j.&nbsp.&j++)&;m;&&N&&&&&nbsp:\n&quot,a[i][j]);&j++)&printf(&printf(&for(j=0;i++)&.h&&a[i][j]=a[i][j+1];\n&&&{&&n;printf(&m);printf(&quot:&#define&n;}&&nbsp.jpg" esrc="&&printf(&a[i][j+1]=t;&&30#define&&&&&;;j++)&&nbsp://g;);for(i=0,&&&scanf(&&nbsp.m;&n);n;i++)&);printf(&&}&\n输入列数m;&&);}&i++)&&&i&lt:&}&t=a[i][j];&nbsp://g;&scanf(&&&{&%d&&&&/zhidao/wh%3D600%2C800/sign=667d6d7aafcd8e2fdbf49b7d/960a304e251f95cacf453dcac9521d;&for(i=0;&M&&{&i++)&);for(j=0;{&&&nbsp,i+1);&nbsp,t;30void&&\n第%d行\n&&&&for(j=0;printf(&&n;&for(i=0.jpg" target="_blank" title="点击查看大图" class="ikqb_img_alink"><img class="ikqb_img" src="m-1-x;int&&\n输入行数n;&&);&j&a[N][M];\n&&}}<a href="\n&&&&for(x=0;x&%d&scanf(&j&&&&&&&&&j&&);i&&%5d&quot,&/zhidao/wh%3D450%2C600/sign=ad43a9f54ef2c82b27a6b4/960a304e251f95cacf453dcac9521d#include&&&{&&i&m;&for(j=0;j&&if(a[i][j]&lt.hiphotos
其他类似问题
为您推荐:
冒泡排序法的相关知识
其他1条回答
#include&iostream&
const int N=50;
void ccin(int *a[N]);
void range(int *a[N]);
void ccout(int *a[N]);
int main()
int *b[N],a[N][N],i;
for(i=0;i&N;i++)
b[i]=a[i];
cout&&&请输入行数&&&
cout&&&请输入列数&&&
void ccin(int *a[N])
for(i=0;i&m;i++)
cout&&&请输入第&&&i+1&&&行&;
for(j=0;j&n;j++)
cin&&*(*(a+i)+j);
void range(int *b[N])
int i,j,k,l;
for(i=0;i&m;i++)
for(l=0;l&n-1;l++)
for(j=0;j&n-1;j++)
if(*(*(b+i)+j)&*(*(b+i)+j+1))
k=*(*(b+i)+j);
*(*(b+i)+j)=*(*(b+i)+j+...
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁共有 1959 人关注过本帖
标题:使用二级指针对字符串数组进行排序(其中冒泡法排序部分是摘抄)有2个问题
来 自:神界
等 级:贵宾
威 望:339
帖 子:10992
专家分:43237
结帖率:99.74%
&&已结贴√
&&问题点数:20&&回复次数:3&&&
使用二级指针对字符串数组进行排序(其中冒泡法排序部分是摘抄)有2个问题
程序代码:#include &stdio.h&
#include &string.h&
#define num 10
int main(void)
&&& char* test[]={&All entries of the table must &,& values of x and y(x) printed as &,
&&&&&&&&&&&&&&&&&&&when mainframes were &,&render any typical double &,
&&&&&&&&&&&&&&&&&&&the summation process note &,&repeated to produce sequences &,
&&&&&&&&&&&&&&&&&&&summing the series above&,&This process of finding &,
&&&&&&&&&&&&&&&&&&&convergence of the summation &,&Numerical Summation of a Series&};
&&& char** p=
&&& char* tmp=NULL;
&&& int i,j,k;
&&& //以下用冒泡法对字符串数组进行排序
&&& for(i=<font color=#;i&num-<font color=#;i++)
&&&&&&&&k=i;
&&&&&&&&for(j=i+<font color=#;j&j++)
&&&&&&&&&&&&if(strcmp(*(p+k),*(p+j))&<font color=#) k=j;
&&&&&&&&&&&&if(k!=i)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&& tmp=*(p+k);
&&&&&&&&&&&&&&& *(p+k)=*(p+i);
&&&&&&&&&&&&&&& *(p+i)=
&&&&&&&&&&&&}
&&& ///////////////////////////////////////////////////////////////////////////////////
&&& //输出排序后的字符串数组
&&& for(i=<font color=#;i&i++)
&&&&&&&&printf(&源串=%-40s&&长度=%d\n&,*p,(int)strlen(*p));
&&&&&&&&p++;
&&& ///////////////////////////////////////////////////////////////////////////////////
&&& return <font color=#;F:\c_source\t2\Debug&fc
源串= values of x and y(x) printed as&&&&&&&&& 长度=33
源串=All entries of the table must&&&&&&&&&&&& 长度=30
源串=Numerical Summation of a Series&&&&&&&&&&&长度=31
源串=convergence of the summation&&&&&&&&&&&&&&长度=29
源串=This process of finding&&&&&&&&&&&&&&&&&& 长度=24
源串=render any typical double&&&&&&&&&&&&&&&&&长度=26
源串=repeated to produce sequences&&&&&&&&&&&& 长度=30
源串=summing the series above&&&&&&&&&&&&&&&&&&长度=24
源串=the summation process note&&&&&&&&&&&&&&& 长度=27
源串=when mainframes were&&&&&&&&&&&&&&&&&&&&& 长度=21
问题1、样例输出的粉色部分 明显不对,不知道代码差哪了(我对排序不熟悉)
看这几句交换代码
&&&&&&&&&&&&&&& tmp=*(p+k);
&&&&&&&&&&&&&&& *(p+k)=*(p+i);
&&&&&&&&&&&&&&& *(p+i)=
我认为,这样的代码交换类似int一类的还可以,交换字符串指针 怎么还可以呢
数组中字符串位置的变动 应该使用类似字符串拷贝一类的东东才能完成啊
搜索更多相关主题的帖子:
等 级:千里冰封
帖 子:1554
专家分:10000
&&得分:20&
交换指针,那就要指针的指针了
控制系统中的C是怎么样的?欢迎来群一起交流进步
来 自:神界
等 级:贵宾
威 望:339
帖 子:10992
专家分:43237
以下是引用pauljames在 20:29:11的发言:
交换指针,那就要指针的指针了我明白了
字符串在内存中的地址实际上并没有发生变化,
还是初始化的位置,但是指向他们的指针的位置发生了变化,所以导致最终可以有序输出
那第一个问题呢 ,这个有序输出 实际上是错误的
DO IT YOURSELF !
来 自:神界
等 级:贵宾
威 望:339
帖 子:10992
专家分:43237
程序代码:#include &stdio.h&
#include &string.h&
#define num 10
int main(void)
&&& char* test[]={&All entries of the table must &,& values of x and y(x) printed as &,
&&&&&&&&&&&&&&&&&&&when mainframes were &,&render any typical double &,
&&&&&&&&&&&&&&&&&&&the summation process note &,&repeated to produce sequences &,
&&&&&&&&&&&&&&&&&&&summing the series above&,&This process of finding &,
&&&&&&&&&&&&&&&&&&&convergence of the summation &,&Numerical Summation of a Series&};
&&& char** p=
&&& ///////////////////////////////////////////////////////////////////////////////////
&&& printf(&一级指针**p的地址是%X&&字符串指针数组test[]的地址是%X\n&,&p,&test);
&&& printf(&一级指针**p的内容是%X&&\n&,p);
&&& for(i=<font color=#;i&i++)
&&&&&&&&printf(&源串=%-35s&&长度=%d 二级指针内容为%X&&test[%d]的地址是%X\n&,*p,(int)strlen(*p),p,i,&test[i]);
&&&&&&&&p++;
&&& ///////////////////////////////////////////////////////////////////////////////////
&&& return <font color=#;
样例输出:
F:\c_source\t2\Debug&fc
一级指针**p的地址是12FF54&&字符串指针数组test[]的地址是12FF58
一级指针**p的内容是12FF58
源串=All entries of the table must&&&&&&&&长度=30 二级指针内容为12FF58&&test[0]的地址是12FF58
源串= values of x and y(x) printed as&&&&&长度=33 二级指针内容为12FF5C&&test[1]的地址是12FF5C
源串=when mainframes were&&&&&&&&&&&&&&&&&长度=21 二级指针内容为12FF60&&test[2]的地址是12FF60
源串=render any typical double&&&&&&&&&&&&长度=26 二级指针内容为12FF64&&test[3]的地址是12FF64
源串=the summation process note&&&&&&&&&&&长度=27 二级指针内容为12FF68&&test[4]的地址是12FF68
源串=repeated to produce sequences&&&&&&&&长度=30 二级指针内容为12FF6C&&test[5]的地址是12FF6C
源串=summing the series above&&&&&&&&&&&& 长度=24 二级指针内容为12FF70&&test[6]的地址是12FF70
源串=This process of finding&&&&&&&&&&&&&&长度=24 二级指针内容为12FF74&&test[7]的地址是12FF74
源串=convergence of the summation&&&&&&&&&长度=29 二级指针内容为12FF78&&test[8]的地址是12FF78
源串=Numerical Summation of a Series&&&&&&长度=31 二级指针内容为12FF7C&&test[9]的地址是12FF7C
DO IT YOURSELF !
版权所有,并保留所有权利。
Powered by , Processed in 0.040507 second(s), 8 queries.
Copyright&, BCCN.NET, All Rights Reserved

我要回帖

更多关于 冒泡法对数组 的文章

 

随机推荐