#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define MAXSIZE 1024
typedef int datatype;
typedef struct
{
datatype data[MAXSIZE];
int top;
}SeqStack;
SeqStack *Init_SqeStack()
{
SeqStack *s;
s=(SeqStack*)malloc(sizeof(SeqStack));
s->top=-1;
return s;
}
int StackEmpty(SeqStack *s)
{
if(s->top==-1)
return 1;
else return 0;
}
int Push(SeqStack *s,datatype x)
{
if(s->top==MAXSIZE-1) return 0;
else
{s->top++;
s->data[s->top]=x;
return 1;
}
}
int Pop(SeqStack *s,datatype *x)
{
if(StackEmpty(s)) return 0;
else{*x=s->data[s->top];
s->top--;
return 1;
}
}
void main( SeqStack *s )
{
SeqStack *s1, *s2;
datatype x;
//将s栈中的内容转移到s1栈中
while( ( s ) != 0 )
{
Pop( s, &x );
Push( s1, x );
}
//将s1栈中的内容转移到s2栈中
while( StackEmpty( s1 ) != 0 )
{
Pop( s1, &x );
Push( s2, x );
}
//将s2栈中的内容转移到s栈中
while( StackEmpty( s2 ) != 0)
{
Pop( s2, &x );
Push( s, x );
}
}