Get the App
SLTechnology News&Howtos  ›  Development  › 

Data structure of PHP linked list

Shulou Source: shulou.com Published: 2022-06-03 19:04:47 10月04日 Update

This article mainly explains "the data structure of PHP linked list". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the data structure of PHP linked list.

Linked list: it is an ordered list, but it is stored separately in memory. Using linked lists can solve problems such as Joseph problem, sorting problem, search problem, generalized list.

One-way linked list, two-way linked list, circular linked list

The bottom layer of PHP is C, when a program is running, the memory is divided into five areas (stack area, stack area, global area, constant area, code area).

Regulation: basic data types, generally placed in the stack area

Compound data types, such as objects, are placed in the heap area

Define a class Hero

Define member attribute ranking $no

Define member attribute name $name

Define the member attribute nickname $nickname

Define the member property $next, which is a reference to the next Hero object

Define the constructor, passing the parameter: $no,$name,$nickname

Create a header head, the head is just a header and does not put in the data

Get the $head object, new Hero ()

Get the first Hero object $hero,new Hero (1, "Song Jiang", "timely Rain")

Connect two objects, $head- > next=$hero

Get the second Hero object $hero2,new Hero (2, "Lu Junyi", "Jade Kirin")

Connect two objects, $hero- > next=$hero2

Traversing linked list

Define a function showHeros (), with the argument $head object

Define a temporary variable $cur to store the $head object

While loop, if $cur- > next is not null

Print it.

Move the pointer back, $cur=$cur- > next

PHP version:

Tags: Object data attribute member data structure structure timely rain name question Song Jiang Jade Kirin two head memory content function parameter type hero storage Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Docker Huawei macOS Xiaomi