数据结构队列作业 以不带头结点的链表表示链栈,写出相应的入栈和出栈算法。 链栈C语言描述如下:

2025-01-16 17:54:00
推荐回答(1个)
回答1:

void Pop(LinkStack *Stack)
{
if (Stack->top == null)
{
printf("the stack is empty\n");
return;
}
SNode *node = Stack->top;

Stack->top = node->next;
free(node);
}

void Push(LinkStack *Stack ,SElemType data)
{
SNode *node = (struct Snode*)malloc(sizeof(Snode));
if (node == NULL)
{
printf("fatal error");
reutrn ;
}

node->data = data;
node->next = Stack->top;
Stack->top = node;
}