关于链栈的链表传递问题
#include <iostream>using namespace std;
//链栈
#define ElemType char
typedef struct LNODE{
ElemType elem;
struct LNODE *next;
}SqStack;
SqStack * InitStack(SqStack *S){
char ch;
SqStack *p;
S=NULL;
ch=getchar( );
while (ch!='\n'){
p=(SqStack*)malloc(sizeof(SqStack));
p->elem=ch;
p->next=S;
S=p;
ch=getchar( );
}
return S;
}
/*void InitStack(SqStack *S){
char ch;
SqStack *p;
S=NULL;
ch=getchar( );
while (ch!='\n'){
p=(SqStack*)malloc(sizeof(SqStack));
p->elem=ch;
p->next=S;
S=p;
ch=getchar( );
}
}*/
void DestoryStack(SqStack *Sq){
SqStack *S;
while(S){
S=Sq;
Sq=Sq->next;
free(S);
}
}
bool GetTop(SqStack *Sq,ElemType &e){
SqStack *S;
S=Sq;
if(!S)return false;
e=S->elem;
return true;
}
SqStack * Push_sq(SqStack *Sq,ElemType e){
SqStack *SNEW;
SNEW=(SqStack *)malloc(sizeof(SqStack));
SNEW->elem=e;
SNEW->next=Sq;
Sq=SNEW;
return Sq;
}
bool Pop_sq(SqStack *Sq,ElemType &e){
SqStack *S;
S=Sq;
if(!S)return false;
e=S->elem;
Sq=Sq->next;
free(S);
return true;
}
void PrintStack(SqStack *Sq){
SqStack *S;
S=Sq;
while(S){
cout<<S->elem<<' ';
S=S->next;
}
cout<<endl;
}
int main(void){
SqStack *S;
ElemType e;
S=InitStack(S);
PrintStack(S);
// S=Push_sq(S,'d');
Pop_sq(S,e);
PrintStack(S);
return 0;
}
POP和PUSH函数作用之后,新的堆栈无法提供给print函数使用,调试发现结构体没有传出来,这是怎么回事,哪里需要修改