#include<iostream>
using namespace std;
struct Node
{
int data;
Node* link;
};
Node* top = NULL;
void Push(int x)
{
Node* temp = new Node;
temp->data = x;
temp->link = top;
top = temp;
}
void Pop()
{
Node* temp;
if(top == NULL) return;
temp = top;
top = top->link;
delete temp;
}
int Top()
{
return top->data;
}
void isEmpty()
{
if(top == NULL) printf("Empty!\n");
else printf("Not Empty!\n");
}
int main()
{
isEmpty();
Push(5);
printf("%d\n",Top());
isEmpty();
Push(3);
printf("%d\n",Top());
isEmpty();
Push(11);
printf("%d\n",Top());
isEmpty();
Pop();
printf("%d\n",Top());
return 0;
}
栈:使用链表实现一个栈
最新推荐文章于 2024-04-01 10:15:03 发布