#include<iostream>
using namespace std;
typedef struct student
{
int data;
struct student * next;
}node;
typedef struct stackqueque
{
node * top, *zhandi;
} Stack;
Stack * push(Stack * stack,int num)
{
node *s = (node *)malloc(sizeof(node));
s->data = num;
s->next = NULL;
if (stack->top==NULL)
{
stack->top = s;
stack->zhandi = s;
}
else
{
stack->top->next = s;
stack->top = s;
}
return stack;
}
int pop(Stack *stack)
{
if (stack->top==NULL)
{
cout << "栈为空" << endl;
return -1;
}
if (stack->top==stack->zhandi)
{
int x = stack->top->data;
stack->top = NULL;
stack->zhandi = NULL;
return x;
}
else
{
node* p = stack->zhandi;
while (p->next!=stack->top)
{
p = p->next;
}
node *q = stack->top;
int x = stack->top->data;
p->next = NULL;
stack->top = p;
free(q);
return x;
}
}
int main()
{
}
C/C++ 知识回顾 栈的入栈与出栈
最新推荐文章于 2023-06-11 16:01:45 发布