BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #37209同步于 2010/3/29
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

一个题目引发的血案....

wm290291928
2010/3/29镜像同步14 回复
完成程序,实现对数组的降序排序 #include <stdio.h> void sort( ); int main() { int array[]={45,56,76,234,1,34,23,2,3}; //数字任//意给出 sort( ); return 0; } void sort( ) { ____________________________________ | | | | |-----------------------------------------------------| } 当看见这个题目的时候,我突然之间眼前一亮,不是因为此题有非常的算法,此题算法无非可用那几种数据结构上的排序方法,但是不管怎么样,其时间复杂无非最快是:log(n) 所以这个题目实际上并没有算法问题,但是这个题目关系到了很多关于c核心技术的东西,最重要的便是修饰符的问题了,当然这个题目中最最重要的,我觉得应该是static和extern的用法~~~包含着相关链接的问题 但是结果出现了血案...我最终并没有完成这个题目的编写 #include <stdio.h> void sort(); main() { static int array[]={45,56,76,234,1,34,23,2,3}; //数字任//意给出 sort(); system("pause"); } void sort() { extern int array[9]; int i,j; int temp; for(i=0;i<=8;i++) for(j=0;j<=i;j++) if(array[j]<array[j+1]){ temp=array[j]; array[j]=array[j+1]; array[j+1]=temp; } } ....出问题出问题了....
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
jmpesp机器人#1 · 2010/3/29
你想说明啥?
fox1987机器人#2 · 2010/3/29
无参数传递。。。。 汗!
jokerlee机器人#3 · 2010/3/29
老题,以前讨论过, 这题和static,extern没啥关系,用的是栈溢出的hack
dasha机器人#4 · 2010/3/29
不仅是老贴,而且还多版了- -
wks机器人#5 · 2010/3/29
#include<stdio.h> #include<string.h> void sort() { int a; char *p; static int array2[]={45,56,76,234,1,34,23,2,3}; //数字任//意给出 static int array3[]={1,2,3,23,34,45,56,76,234}; //数字任//意给出 p=(char*)&a; while(p++) { if(memcmp(p,array2,sizeof(array2))==0) { memcpy(p,array3,sizeof(array3)); return; } } } int main() { int i; int array1[]={45,56,76,234,1,34,23,2,3}; //数字任//意给出 sort(); for(i=0;i<8;i++) { printf("%d\n",array1[i]); } return 0; } 这个居然能编译通过而且居然能运行出来。。。。
dasha机器人#6 · 2010/3/29
这个真YD,不过如果是p--才能找到的话怎么办... 【 在 wks 的大作中提到: 】 : #include<stdio.h> : #include<string.h> : void sort() { : ...................
wks机器人#7 · 2010/3/29
我一开始真以为是p--,结果segment fault了。然后才想起来栈是往低地址方向扩张的 【 在 dasha 的大作中提到: 】 : 这个真YD,不过如果是p--才能找到的话怎么办...
dudu66机器人#8 · 2010/3/30
这个样子啊,学习...
lichehuo机器人#9 · 2010/3/30
【 在 wks 的大作中提到: 】 : #include<stdio.h> : #include<string.h> : void sort() { : ................... 这个太强悍了,我看不懂,问我大哥,我大哥告诉我说需要的知识太多了,让我再看一年的书再问他。。。。。。。。。。。