Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Data structure of PHP linked list

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report