Data structure:
Stack is a special linear table that allows insertion and deletion at the same end. One end that allows the insert and delete operations is called the top, and the other end is the bottom of the stack. The bottom of the stack is fixed, while the top of the stack is floating; when the number of elements in the stack is zero, it is called an empty stack. Insert is generally called push and delete is called pop ). Stack is also known as a forward, forward, and forward table.
Operating System:
The compiler automatically assigns release, stores function parameter values, and local variable values. The operation method is similar to the stack in the data structure.
The stack uses a level-1 cache, which is usually in a bucket When called, and is immediately released after the call is completed.
Double-end stack template code:
# Define true 1 # define false 0 # define M 100 typedef struct {stackelementtype stack [m]; stackelementtype top [2]; /* Top [0] and top [1] are two stack top Indicators Respectively */} dqstack;/* initialization operation. */Void initstack (dqstack * s) {S-> top [0] =-1; s-> top [1] = m;}/* stack operations. */INT push (dqstack * s, stackelementtype X, int I) {/* press Data Element x into the I stack */If (S-> top [0] + 1 = s-> top [1]) /* stack full */Return (false); Switch (I) {Case 0: S-> top [0] ++; s-> stack [S-> top [0] = x; break; Case 1: S-> top [1] --; s-> stack [S-> top [1] = x; break; default:/* parameter error */Return (false)} return (true );} /* stack output. */Int pop (dqstack * s, stackelementtype * X, int I) {/* the top elements of the stack are displayed from stack I and sent to stack x */switch (I) {Case 0: If (S-> top [0] =-1) Return (false); * x = s-> stack [S-> top [0]; s-> top [0] --; break; Case 1: If (S-> top [1] = m) Return (false ); * x = s-> stack [S-> top [1]; S-> top [1] ++; break; default: Return (false );} return (true );}
Stack operation-double-ended sequential Stack