问题遇到的现象和发生背景
链式栈无法进行压栈和出栈
用代码块功能插入代码,请勿粘贴截图
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef char DataType;
typedef struct Node{
DataType ele;
struct Node *link;
}StackNode;
void initStack(StackNode *S){
S=NULL;
}
bool pushStack(StackNode *S,DataType data){
StackNode *p =(StackNode*)malloc(sizeof(StackNode));
if(p==NULL){
printf("创建节点失败\n");
return false;
exit(1);
}
p->ele=data;
p->link=S;
S=p;
return true;
}
bool isEmpty(StackNode *S){
if(S==NULL){
return true;
}else{
return false;
}
}
bool pop(StackNode *S,DataType *x){
if(isEmpty(S)){
return false;
}
StackNode *p=S;
*x=p->ele;
S=p->link;
return true;
}
int main()
{
StackNode S;
char x;
pushStack(&S,'o');
printf("%c",S.ele);
return 0;
}