/*链栈的运算,包括进栈。退栈,输出栈中的所有元素。 程序如下:*/
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int date;
struct node *next;
}Lsnode;
/*进栈*/
Lsnode *push(Lsnode *top,int x)
{
Lsnode *p=(Lsnode *)malloc(sizeof(Lsnode));
p->data=x;
p->next=top;
return p;
}
/*退栈*/
Lsnode *pop(Lsnode *top,int *x)
{
Lsnode *p=top;
if(p==NULL)
return 0;
*x=p->data;
top=p->next;
free(p);
return top;
}
void prints(Lsnode *top)
{
Lsnode *p=top;
printf("stack is:");
while(p){
printf("%d",p->data);
p=p->next;
}
printf("\n");
}
void main(){
Lsnode *top=NULL;
int choice=0,x;
while(choice<4){
printf("0:ends");
printf("1:push");
printf("2:pop");
printf("3:output data of stack");
printf("choice");
scanf("%d",&choice);
switch(choice)
{
case 0:break;
case 1:printf("output data that has pushed x:");
scanf("%d",&x);
push(top,x);
break;
case 2:if(top){
printf("stack empty");
top=pop(top,&x);
printf("poprf value is %d",x);
break;}
case 3:
prints(top);
break;
}
if(choice==0)break;
}
为什么报错H:\c语言编程\stack.cpp(15) : error C2039: 'data' : is not a member of 'node'
H:\c语言编程\stack.cpp(6) : see declaration of 'node'
H:\c语言编程\stack.cpp(25) : error C2039: 'data' : is not a member of 'node'
H:\c语言编程\stack.cpp(6) : see declaration of 'node'
H:\c语言编程\stack.cpp(36) : error C2039: 'data' : is not a member of 'node'
H:\c语言编程\stack.cpp(6) : see declaration of 'node'
H:\c语言编程\stack.cpp(72) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错