Home > Backend Development > PHP Tutorial > 'Stack' for PHP programmers to learn data structures and algorithms

'Stack' for PHP programmers to learn data structures and algorithms

WBOY
Release: 2016-07-29 09:13:09
Original
915 people have browsed it

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.

 

 

PHP 程序员学数据结构与算法之《栈》

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

   

PHP 程序员学数据结构与算法之《栈》

Analysis

Through the definition and process, we analyze the data structure (red logo), action part (blue logo), and action rules (yellow logo).

PHP 程序员学数据结构与算法之《栈》

PHP 程序员学数据结构与算法之《栈》

PHP 程序员学数据结构与算法之《栈》

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). PHP 程序员学数据结构与算法之《栈》

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

PHP 程序员学数据结构与算法之《栈》

Encoding

PHP 程序员学数据结构与算法之《栈》

PHP 程序员学数据结构与算法之《栈》

Summary

PHP 程序员学数据结构与算法之《栈》

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.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template