数据结构有如下链式栈的结构体定义,设计进栈push和出栈函数pop。(提示:可在函数框架中补充完整代码,也可自行设计代码) typedef struct StackNode{ /* 定义栈的结点结构类型 */ int data; struct StackNode *next; }Node,*LinkStack; status push(LinkStack &S, elemtype e) { Node *p; //填写代码 return OK; } status pop
时间: 2023-06-02 13:05:35 浏览: 119
数据结构--栈的链式实现
, int data)
{
Node *newNode = (Node *)malloc(sizeof(Node));
if(newNode == NULL) return ERROR;
newNode->data = data;
newNode->next = stack;
stack = newNode;
return OK;
}
status pop(LinkStack &stack, int &data)
{
if(stack == NULL) return ERROR;
Node *popNode = stack;
data = stack->data;
stack = stack->next;
free(popNode);
return OK;
}
阅读全文