How to Implement Linked List in PHP?

General discussion on PHP
Post Reply
addi6008
Posts: 2
Joined: Thu Sep 01, 2016 5:44 am
Contact:

How to Implement Linked List in PHP?

Post by addi6008 » Thu Sep 01, 2016 6:26 am

Hello Guys,
I've recently read about Linked List data structure from my course book and I find it quite impressive. My Professor has teach us data structure in C with the help of Structures and Pointers. I think of Implementing Linked List in PHP. Well I create class for the management of Nodes but still I'm in confusion cause I don't know about anything that can replace the pointer scheme of C/C++. So, Please help me to figure out appropriate solution for this problem.
I've only create following set of code.

Code: Select all

<?php
class LinkedList
{
   public $node;
   private $pointerToNode;//I've just renamed it as pointer to node that i want to replace with something relevant in PHP

   public insertNode($nodeValue, $ref="InsertLast")
    {
          $this->node=$nodeValue; //

          //rest of code that insert the node and linked it to the next existing node
     }
}


tedtiger
Posts: 244
Joined: Thu Mar 05, 2009 4:59 pm
Location: Germany
Contact:

Re: How to Implement Linked List in PHP?

Post by tedtiger » Thu Sep 01, 2016 8:32 am

There are no pointers in PHP. Just use arrays and traverse them as needed.

Post Reply