# Include <iostream. h>
# Define STACK_INIT_SIZE 10 // initial storage allocation
Struct Dblstack {
Int * base1;
Int * base2;
Int * top1;
Int * top2;
Int stacksize; // The currently allocated storage space, in the unit of Elements
};
Int Initstack (Dblstack & s)
{// Construct an empty sequential stack s
S. base1 = new int [STACK_INIT_SIZE];
If (! S. base1) {cout <"memory application failed! N "; return 0 ;}
S. top1 = s. base1 + 1;
S. stacksize = STACK_INIT_SIZE;
S. base2 = s. base1 + s. stacksize;
S. top2 = s. base2-1;
Return 1;
}
Int emptystack (Dblstack & s, int I)
{// Judge whether the stack is empty. 1 is returned; otherwise, 0 is returned.
If (I = 1 & s. top1 = s. base1 + 1 | I = 2 & s. top2 = s. base2-1)
Return 1;
Else return 0;
}
Int fullstack (Dblstack & s)
{// Check whether the stack is full. If the stack is full, 1 is returned. Otherwise, 0 is returned.
If (s. top1 = s. top2) return 1;
Else return 0;
}
Int push (Dblstack & s, int I, int x)
{// Insert element x as the new top element of the stack
If (fullstack (s) {cout <"stack full n"; return 0 ;}
Else {
If (I = 1) {cout <"the insert operation is successful! Nn "; * s. top1 ++ = x ;}
If (I = 2) {cout <"the insert operation is successful! Nn "; * s. top2 -- = x ;}
} Return 1;
}
Int pop (Dblstack & s, int I, int & x)
{// If the stack is not empty, the top element of stack in stack I is deleted and x is returned. Otherwise, 0 is returned.
If (emptystack (s, I) return 0;
Else {
If (I = 1) {cout <"Stack output successful! The output stack element is: "; x = * -- s. top1 ;}
If (I = 2) {cout <"Stack output successful! The output stack element is: "; x = * ++ s. top2 ;}
} Return 1;
}
Int gettop (Dblstack & s, int I, int & x)
{// If the stack is not empty, use x to return the top element of the stack and the true element; otherwise, return 0.
If (emptystack (s, I) return 0;
Else {
If (I = 1) {x = * (s. top1-1); cout <"n out stack successful! Stack top :";}
If (I = 2) {x = * (s. top2 + 1); cout <"n stack output successful! Stack top :";}
} Return 1;
}
Int clearstack (Dblstack & s)
{// If the stack is empty, 1 is returned. Otherwise, 1 is returned after the stack is empty.
If (emptystack (s, 1) & emptystack (s,
<