#include<stdlib.h>
#include<stdio.h>
//所有的函数中由于对局部变量进行操作,所以全部是指针,即&a
typedef struct node{
//struct node *front;
struct node *next;
int date;
}Link;
typedef struct _node{
struct node *top;
struct node *base;
}Line;
int main()
{
void InitStack(Line *stack);
void DestroyStack(Line *stack);
void ClearStack(Line *stack);
bool StackEmpty(Line *stack);
int StackLength(Line *stack);
int GetTop(Line *stack);
void Push(Line *stack,int number);
void Pop(Line *stack);
Line a;
InitStack(&a);
//ClearStack(&a);
//DestroyStack(&a);
//printf("%d",a.top->date);
//Push(&a,6);
//Pop(&a);
//printf("%d",a.top->date);
//printf("%d",GetTop(&a));
return 0;
}
void InitStack(Line *stack)
{
Link *head=NULL;
Link *tail=head;
int number;
do{
scanf("%d",&number);
if(number==-1){
break;
}
Link *p=(Link *)malloc(sizeof(Link));
p->date=number;
p->next=NULL;
if(!tail){
head=p;
tail=head;
}
else {
while(tail->next)
{
tail=tail->next;
}
tail->next=p;
}
}while(number!=-1);
Link *p=head;
while(p->next)
{
p=p->next;
}
stack->top=p;
stack->base=head;
}
void DestroyStack(Line *stack)
{
Link *p=stack->base;
Link *pt=stack->base->next;
while(pt->next)
{
free(p);
p=pt;
pt=pt->next;
}
free(p);
free(pt);
}
void ClearStack(Line *stack)
{
Link *p=stack->base->next;
Link *pt=stack->base->next->next;
while(pt->next)
{
free(p);
p=pt;
pt=pt->next;
}
free(p);
free(pt);
stack->top=stack->base;
stack->top->date=-1;
}
bool StackEmpty(Line *stack)
{
if(stack->base)return true;
else return false;
}
int StackLength(Line *stack)
{
int ans=0;
Link *p=stack->base;
while(p)
{
ans++;
p=p->next;
}
return ans;
}
int GetTop(Line *stack)
{
return stack->top->date;
}
void Push(Line *stack,int number)
{
Link *p=(Link *)malloc(sizeof(Link));
p->date=number;
p->next=NULL;
stack->top->next=p;
stack->top=p;
}
void Pop(Line *stack)
{
Link *p=stack->base;
while(p->next->next)
{
p=p->next;
}
free(stack->top);
stack->top=p;
}