Code:
#include <iostream>
#include <stdio.h>
#include <malloc.h>
using namespace std;
const int N = 100010;
typedef int Status;
typedef struct StackNode
{
int data;
struct StackNode *next;
}
StackNode, *LinkStack;
void Init_LinkStack(LinkStack & S)
{
S = NULL;
}
Status Empty_Stack(LinkStack & S)
{
if(S == NULL) return true;
return false;
}
Status Push_Stack(LinkStack & S, int e)
{
StackNode *p = (LinkStack) malloc (sizeof(StackNode));
p->data = e;
p->next = S;
S = p;
return true;
}
Status Pop_Stack(LinkStack & S, int & e)
{
StackNode *p;
if(S == NULL) return false;
e = S->data;
p = S;
S = S->next;
delete(p);
return true;
}
Status GetTop_Stack(LinkStack & S)
{
if(S == NULL) return false;
return S->data;
}
signed main()
{
int n, m;
cin >> n;
StackNode *S;
Init_LinkStack(S);
for(int i = 1; i <= n; i ++ )
{
int x;
scanf("%d", &x);
Push_Stack(S, x);
}
while(!Empty_Stack(S))
{
cout << GetTop_Stack(S) << ' ';
Pop_Stack(S, m);
}
}