typedef struct StackRecord *Stack;
struct StackRecord  {
    int Capacity;       /* maximum size of the stack array */
    int Top1;           /* top pointer for Stack 1 */
    int Top2;           /* top pointer for Stack 2 */
    ElementType *Array; /* space for the two stacks */
}
Stack CreateStack( int MaxElements ) {
	Stack S=(Stack)malloc(sizeof(struct StackRecord));
	S->Top1=-1;
	S->Top2=MaxElements;
	S->Capacity=MaxElements;
	S->Array=(int *)malloc(sizeof(int)*MaxElements);
	return S;
}
int IsEmpty( Stack S, int Stacknum ) {
	if(Stacknum==1) {
		if(S->Top1==-1)
			return 1;
		return 0;
	} else {
		if(S->Top2==S->Capacity) return 1;
		else return 0;
	}
}
int IsFull( Stack S ) {
	if(S->Top2-S->Top1==1) {
		return 1;
	}
	return 0;
}
int Push( ElementType X, Stack S, int Stacknum ) {
	if(IsFull(S))
		return 0;
	if(Stacknum==1) {
		S->Array[++S->Top1]=X;
		return 1;
	}
	S->Array[--S->Top2]=X;
	return 1;
}
ElementType Top_Pop( Stack S, int Stacknum ) {
	if(IsEmpty(S,Stacknum)) {
		return ERROR;
	}
	if(Stacknum==1)
		return S->Array[S->Top1--];
	return S->Array[S->Top2++];
}