PHP Programmer's data structure and algorithm "stack"

Source: Internet
Author: User
Introduced

"To become a master, will practice this work."

To be a good programmer, data structures and algorithms are the required content. And now the Web programmers use traditional algorithms and data structures are relatively small, because many of the algorithms are packaged, not to worry about specific implementation details, such as PHP stack operation Array_pop, the stack operation Array_push, have the specified library functions, leads to less research on the underlying algorithms and, ultimately, as a tool puppet.

So I suggest more coder to start learning from the basics. This is the first thing we know about the stack operation began , let us familiar with the stack.

  

 

What is the stack?

The formula "last first out", this is my deepest impression of a sentence, but also the teacher a piece of explanation, the most impressive.

Definition: A stack is a linear table that restricts insertions and deletions to occur only in one place, at the end of the linear table, called the top of the stack.

Process: First entered data is pressed into the bottom of the stack, the final data at the top of the stack, need to read the data from the top of the stack to eject the data (the last data is read out first).

      

Analysis

Through the definition and process, we analyze the data structure (red identification), the action part (blue identification), and the Rules of the action (yellow identification).

Please look

constituent components

Data: Linear table (saved with array structure named data), End index (named End with int structure, initial value null--because there is no element in the start linear table, so there is no end index so to speak, And because of the constant fetching of data, adding data, this end is the element of change. )。

Action (method): Press-in (push: rule, placed on the last side of the linear table), pops up (pop: rule, takes out from the last, and the end position moves forward).

Coding

Run results

Summarize

The above is my analysis of the stack of the process, because I am a php coder, so I use the angle of PHP to analyze and encode.

If the C language is to be encoded, the array should specify the maximum width, because the C-language array does not grow on its own as the PHP array, and must have an initial width.
Thank you for Chuanshan a submission.

The above describes the PHP Programmer's data structure and algorithm of the "stack", including the beginning, indexing content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.