PHP SPL standard library data structure stack (splstack) Introduction _php Tutorial

Source: Internet
Author: User
Tags spl

PHP SPL standard library data structure stack (Splstack) Introduction


This article mainly introduces the PHP SPL standard library data structure stack (splstack) Introduction, stack (stack) is a special linear table, because it can only at one end of the linear table to insert or delete elements (i.e., into the stack and out of the stack), the need for friends can refer to the next

A stack is a special linear table because it can only insert or delete elements at one end of a linear table (that is, the stack and the stack)

Splstack is the inherited doubly linked list (spldoublylinkedlist) implementation stack.

The class summary is as follows:

Simple to use as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

Think of the stack as an inverted array

$stack = new Splstack ();

/**

* The difference between the visible stack and the doubly linked list is that Iteratormode has changed, and the stack's Iteratormode can only be:

* (1) spldoublylinkedlist::it_mode_lifo | Spldoublylinkedlist::it_mode_keep (default value, data save after iteration)

* (2) Spldoublylinkedlist::it_mode_lifo | Spldoublylinkedlist::it_mode_delete (data deduplication after iteration)

*/

$stack->setiteratormode (Spldoublylinkedlist::it_mode_lifo | Spldoublylinkedlist::it_mode_delete);

$stack->push (' a ');

$stack->push (' B ');

$stack->push (' C ');

$stack->pop (); Out of the stack

$stack->offsetset (0, ' first ');//index to 0 is the last element

foreach ($stack as $item) {

Echo $item. Php_eol; First A

}

Print_r ($stack); Test Iteratormode

http://www.bkjia.com/PHPjc/1000109.html www.bkjia.com true http://www.bkjia.com/PHPjc/1000109.html techarticle PHP SPL standard library data structure stack (Splstack) Introduction This article mainly introduces the PHP SPL standard library data structure stack (splstack) Introduction, stack (stack) is a special linear table, because it can only ...

  • Related Article

    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.