#include<stdio.h>
#include<stdlib.h>
//头结点接栈顶
typedef int E;
typedef struct ListNode * Node;
struct ListNode{
E element;
struct ListNode *next;
};
//初始化,见链表
void initList(Node node)
{
node->next=NULL;
}
//入栈
//变量头结点,入栈元素
int pushStack(Node head,E element)
{
Node node=malloc(sizeof(struct ListNode));
if(node==NULL)
{
return 0;
}
node->element=element;
node->next=head->next;
head->next=node;
return 1;
}
//出栈
//变量头结点
int popStack(Node head)
{
if(head->next==NULL)
{
return 0;
}
Node tmp = head->next;
head ->next=head->next->next;
free(tmp);
}
int main()
{
struct ListNode head;
initList(&head);
for(int i = 1;i<5;i++)
{
pushStack(&head,i);
printf("%d\n",head.next->element);
}
popStack(&head);
printf("%d\n",head.next->element);
}