Implement linked list in php

后端 未结 8 682
小蘑菇
小蘑菇 2020-12-08 05:22

How should I implement a linked list in PHP? Is there a implementation built in into PHP?

I need to do a lot of insert and delete operations, and at same time I need

8条回答
  •  遥遥无期
    2020-12-08 05:44

    Just to clarify, implementing linked list in PHP using PHP arrays probably is not a good idea, because PHP array is hash-table under the hood (not simple low-level arrays). Simultaneously, you don't get advantages of pointers.

    Instead, you can implement data structures like linked list for PHP using extensions, that means you are implementing a data structure in C to PHP.

    Spl data structures are an example, another example is php-ds extension, specially in case of linked lists, you can use this: https://www.php.net/manual/en/class.ds-sequence.php

    Sequence ADT is the unification of List ADT and Vector ADT, so you can use Sequence ADT implemented data structures as lists.

    Hope this could help someone choose wisely.

提交回复
热议问题