楼主:
f422661 (恩恩)
2015-12-14 00:27:10开发平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
问题(Question):
stack push 失败
明明用除错看push return top 都是成功把值放到stack里的
结果一return回main function top又是指向null而不是我push进去的node
求各位大大帮忙指点问题了..
喂入的资料(Input):
3 ,5
预期的正确结果(Expected Output):
3,5
错误结果(Wrong Output):
无
程式码(Code):(请善用置底文网页, 记得排版)
struct node {
int data;
struct node *next;
};
typedef struct node Node;
Node* push(Node* top, int item);
void show(Node* a);
int _tmain(int argc, _TCHAR* argv[])
{
Node *top=NULL;
push(top,3);
push(top,5);
show(top);
return 0;
}
Node* push(Node* top, int item) {
Node* temp;
temp = (Node*) malloc(sizeof(Node));
temp->data = item;
temp->next = top;
top = temp;
return top;
}
void show(Node* top)
{
Node* tmpnode;
tmpnode = top;
printf("\n堆叠内容:");
while(tmpnode != NULL) {
printf("%d ", tmpnode->data);
tmpnode = tmpnode->next;
}
}
补充说明(Supplement):