求求各位大佬了,为什么a返回的是地址啊!
#include<stdio.h>
#include<stdlib.h>
typedef int Status;
typedef int ElemType;
#define TRUE 1;
#define ERROR 0;
typedef struct Node
{
ElemType data;
struct Node* next;
}StackNode,*StackList;
Status InitStack(StackList S); //初始化(无头结点)
Status Push(StackList S, ElemType e); //头插法
Status Pop(StackList S, ElemType* a); //弹出
int main()
{
int n;
ElemType e, a;
StackList S;
S = (StackList)malloc(sizeof(StackNode));
if (InitStack(S) == 1)
{
printf("恭喜!构建空链栈成功!\n");
}
printf("请输入插入元素个数:");
scanf("%d", &n);
printf("请输入插入栈的元素:");
for (int i = 0; i < n; i++)
{
scanf("%d", &e);
Push(S, e);
}
printf("恭喜你!插入成功!\n");
if (Pop(S, &a) == 1)
{
printf("恭喜你!出栈成功!\n");
printf("删除栈顶元素:%d\n", a);
}
return 0;
}
Status InitStack(StackList S)
{
S = NULL;
return TRUE;
}
Status Push(StackList S, ElemType e)
{
StackList P;
P = (StackList)malloc(sizeof(StackNode));
P->data = e;
P->next = S->next;
S = P; //修改栈定指针
return TRUE;
}
Status Pop(StackList S, ElemType *a)
{
StackList P;
P = S;
if (P == NULL)
return ERROR;
*a = S->data;
S = S->next;
free(P);
return TRUE;
}