正在加载图片...
/if you define the"Correct"function like that //Debug will show that the push action doesnt take effection if(head ->next==NULL) printf("The stack is empty. In") head=head->next free(p) //void correct(struct Stack* head, enum Boolean &tag) void correct(enum Boolean &tag) printf("Please enter a bds: " for(i=0; y!=\n; 1++) scanf("%c", &y) if(=)&&head->data==()‖(y=&&head->data==D)‖(y=}&&head->data=={) popo else if((y=oll(y==Dll(y==D) push(y) /*调试程序显示,y并没有被推入堆栈中。即head->data的值在Push中显示为y的值,但是出Pus函数 马上变成Nul* continue: thead->next==NULL ∥原来的程序是i(head=NUL)tag=TRUE; tag=FALSE /总结:由于head为全局变量,所以不应该将其再次作为函数的变量。因为C语言的函数变量是传值机 制,所以在函数中对参数进行了拷贝复本,所以不能改变head的数值。*8 } // if you define the "Correct" function like that //Debug will show that the Push action doesn’t take effection void pop() { if(head->next==NULL) printf("The stack is empty.\n"); else { p=head; head=head->next; free(p); } } //void correct(struct Stack* head,enum Boolean &tag) void correct(enum Boolean &tag) { int i; char y; printf("Please enter a bds:"); for(i=0;y!='\n';i++) { scanf("%c",&y); if((y==')'&&head->data=='(')||(y==']'&&head->data=='[')||(y=='}'&&head->data=='{')) pop(); else if((y=='(')||(y=='[')||(y=='{')) push(y); /*调试程序显示,y 并没有被推入堆栈中。即 head->data 的值在 Push 中显示为 y 的值,但是出 Push 函数。 马上变成 Null。*/ else continue; } if(head->next==NULL) //原来的程序是 if(head ==NULL) tag=TRUE; tag=TRUE; else tag=FALSE; } /*总结: 由于 head 为全局变量,所以不应该将其再次作为函数的变量。因为 C 语言的函数变量是传值机 制,所以在函数中对参数进行了拷贝复本,所以不能改变 head 的数值。*/
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有