Stack operation-double-ended sequential Stack

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.