Introduction
"If you want to become a master, you must practice this skill."
To become an excellent programmer, data structures and algorithms are compulsory courses. Today's Web programmers use relatively few traditional algorithms and data structures, because many algorithms are packaged and we do not need to worry about specific implementation details. For example, PHP's stack operation array_pop and push operation array_push are all specified. Library functions have led to us doing less and less research on basic algorithms, and in the end we have become just a puppet of a tool.
So I still recommend that more coders start learning from the basics. In this article, we will start by talking about the stack operations we are most familiar with, so that we can become familiar with the stack.
What is a stack?
The mantra "last in, first out" is the sentence that impressed me the most, and it was also the most impressive thing in the teacher's explanation. Definition: A stack is a linear list that limits insertion and deletion to only one position. This position is the end of the linear list and is called the top of the stack. Process: The data that enters first is pushed to the bottom of the stack, and the last data is on the top of the stack. When data needs to be read, data is popped from the top of the stack (the last data is read out first).
Analysis
Through the definition and process, we analyze the data structure (red logo), action part (blue logo), and action rules (yellow logo).Please see
成 ingredient ingredients Data: Linear table (named it with the Array structure), and the end
(use the int structure to be named END, the initial value is NULL -because because At first, the linear table has no elements, so there is no end
index, and due to continuous data acquisition and addition, this end is a changing element).
Action (method): push (push: rule, placed at the end of the linear table), pop (pop: rule, taken out from the end, and the end position moves forward). Encoding
Summary
The above is my analysis and understanding process of the stack, because I am a php coder , so I use PHP to analyze and code.If you are coding in C language, the array should specify the maximum width, because C language arrays cannot grow by themselves like PHP arrays, and must have an initial width.
Thanks to Chuanshanjia for contributing.
The above has introduced the "Stack" for PHP programmers to learn data structures and algorithms, including getting started and indexing. I hope it will be helpful to friends who are interested in PHP tutorials.