跳舞般的吴四一cG
娄国栋
关注数: 1
粉丝数: 7
发帖数: 612
关注贴吧数: 3
BBS Test 发帖看下效果。
太搞笑了 sky习惯性的拉能民... 不过没啥用 哈哈
主要是那个幻像让bm 一直输出 太伤了 rt
开始跑狼起了 r rt
Ted 不升冰塔就惨了。。别当bm只封家...
足球的mf更精髓。。 rt
sky mf很精髓 rt
哥们搞了个超星vip,需要啥资料告诉我啊 (计算机方面的) 一个人用太浪费了
日了 原来我的代码漏洞百出..... 1.strcpy的实现代码 char * strcpy(char * strDest,const char * strSrc) { if ((strDest==NULL)||(strSrc==NULL)) file://[/1] throw "Invalid argument(s)"; //[2] char * strDestCopy=strDest; file://[/3] while ((*strDest++=*strSrc++)!='\0'); file://[/4] return strDestCopy; } 错误的做法: [1] (A)不检查指针的有效性,说明答题者不注重代码的健壮性。 (B) 检查指针的有效性时使用((!strDest)||(!strSrc))或(!(strDest&&strSrc)),说明答题者对C语言中类型的隐式转换没有深刻认识。在本例中char *转换为bool即是类型隐式转换,这种功能虽然灵活,但更多的是导致出错概率增大和维护成本升高。所以C++专门增加了bool、true、false 三个关键字以提供更安全的条件表达式。 (C)检查指针的有效性时使用((strDest==0)||(strSrc==0)),说明答题者不知道使用常量的好处。直接使用字面常量(如本例中的0)会减少程序的可维护性。0虽然简单,但程序中可能出现很多处对指针的检查,万一出现笔误,编译器不能发现,生成的程序内含逻辑错误,很难排除。而使用NULL代替0,如果出现拼写错误,编译器就会检查出来。 [2] (A)return new string("Invalid argument(s)");,说明答题者根本不知道返回值的用途,并且他对内存泄漏也没有警惕心。从函数中返回函数体内分配的内存是十分危险的做法,他把释放内存的义务抛给不知情的调用者,绝大多数情况下,调用者不会释放内存,这导致内存泄漏。 (B)return 0;,说明答题者没有掌握异常机制。调用者有可能忘记检查返回值,调用者还可能无法检查返回值(见后面的链式表达式)。妄想让返回值肩负返回正确值和异常值的双重功能,其结果往往是两种功能都失效。应该以抛出异常来代替返回值,这样可以减轻调用者的负担、使错误不会被忽略、增强程序的可维护性。 [3] (A)忘记保存原始的strDest值,说明答题者逻辑思维不严密。 [4] (A)循环写成while (*strDest++=*strSrc++);,同[1](B)。 (B)循环写成while (*strSrc!='\0') *strDest++=*strSrc++;,说明答题者对边界条件的检查不力。循环体结束后,strDest字符串的末尾没有正确地加上'\0'。
四则混合运算算法 功能:输入一行四则运算字符串,输出结果 eg: 输入:3+4*5-2/4 输出:22.5 算法概要: 建立两个动态栈A,B。A存放计算对象,B存放计算符号。 1.当遇到数字字符转化为数字压入A,遇到符号判断符号和B栈顶元素的优先级,若栈顶元素优先级不低于该符号,取出栈顶元素,从栈A中取出两个数字计算,将结果压入栈A。继续直到B栈顶元素比该符号优先级低或将栈B取空。 2.若B栈顶元素低于该运算符,直接将此符号压入栈B。 3.不断从栈B中取运算符,从栈A中取数字计算,结果压入栈A。直到栈B为空。栈A中的数字即为结果。
happy 杀bm很漂亮 rt
sky WCG后明显放开了 哈哈 加油!
【求教】遇到难题了! input 函数出错了,但不知道错在哪里。请高手指点下! /*2.10算法实现*/ #include<stdio.h> typedef struct sqlist/*线性表结构*/ { int *elem; int length; int listsize; }sqlist; /////////////////////////// /*建立线性表*/ ///////////////////////////// sqlist *sqlistbuild() { sqlist *a; a=(sqlist *)malloc(sizeof(sqlist)); a->elem=(int *)malloc(10*sizeof(int)); a->length=0; a->listsize=10; return a; } //////////////////////////// /*向线性表内插入一个单位*/ ///////////////////////////// void input(int n,sqlist *a) { if(a->length==a->listsize) { printf("List has empty!!"); exit(1); } *(a->elem+a->length)=n; a->length++; } /////////////////////////////// /*主函数*/ /////////////////////////////// void main() { sqlist *sqlistbuild(); void input(int n,sqlist *a); sqlist *a; int i; void deln(sqlist *a,int i,int n); a=sqlistbuild(); for(i=0;i<10;i++) input(i,a); deln(a,3,4); for(i=0;i<a->elem;i++) printf("%6d",*(a->elem+5)); } /*删掉线性表第i个单位起的n个单位*/ void deln(sqlist *a,int i,int n) { int j=i,k=0; for(;i<=j+n && (i+n)<=a->listsize;i++) { *(a->elem+i-1)=*(a->elem+i+n-1); k++; } a->length-=k; } /////////////////////////////// ////////////////////////////////
【求助】哪位有C语言的编程练习啊? RT 共享一下!
【求教】二叉树遍历问题 程序其他部分没有问题,标星号的那一块非递归中序遍历老是不行,百思不得其解,望高手指点!! #include<stdio.h> #define LEN sizeof(student) ////////////////////////// /*二叉树结点 */ ///////////////////////// typedef struct student { int num; struct student *rchild,*lchild,*parents; }student,*stup; ///////////////////////////// /*栈接口*/ /////////////////////////////// typedef struct nodepointer { stup *base,*top; int size,maxsize; }nodepointer; /////////////////////////// /*建立栈 (存放结点指针)*/ /////////////////////////// void buildstack(nodepointer *p1) { stup *p; p=(stup *)malloc(sizeof(stup)*10); p1->base=p1->top=p; p1->size=0; p1->maxsize=10; } /////////////////////////// /*将一个二叉树结点指针压入栈顶*/ //////////////////////////// void push(nodepointer *p1,stup p2) { if(p1->top-p1->base==p1->maxsize) { p1->base=(stup *)realloc(p1,p1->maxsize+sizeof(stup)*10); p1->maxsize=p1->maxsize+sizeof(stup)*10; } *(p1->top)=p2; p1->top++; p1->size++; } /////////////////////////////////// /*将栈顶端数据取出 */ /////////////////////////////////// stup gettop(nodepointer *p) { if(p->top==p->base) { printf("Stack is enpty!\n"); return NULL; } return(*(p->top-1)); } //////////////////////////////////// /*退栈*/ /////////////////////////////////// void pop(nodepointer *p) { if(p->top==p->base) { printf("strck is empty!\n"); exit(1); } p->top--; p->size--; } ///////////////////////////////////// //////////////////////////////////// nodepointer *n1,n2; void main() { stup buildtree(); stup inputl(stup parents,stup lchild,stup rchild); stup inputr(stup parents,stup lchild,stup rchild); void traversal(stup p,void(*print)(stup q)); void traversal2(stup p,void(*print)(stup q)); void print(stup p); stup head,p21,p22,p31,p32,p33,p34; head=buildtree(); p21=inputl(head,NULL,NULL); traversal(head,print); p22=inputr(head,NULL,NULL); traversal(head,print); p31=inputl(p21,NULL,NULL); traversal(head,print); p32=inputr(p21,NULL,NULL); traversal(head,print); p33=inputl(p22,NULL,NULL); traversal(head,print); p34=inputr(p22,NULL,NULL); traversal(head,print); printf("*****************\n"); traversal2(head,print); } ///////////////////////// ///////////////////////// stup buildtree()/*建立根结点*/
哎 越学越觉得自己菜.... RT
1
下一页