Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make a Circular linked list in php?
    primarykey
    data
    text
    <p>I have made a single linkedlist in php now i wish to make it circular , any help is really appreciated</p> <p>code for linkedList</p> <pre><code>class listNode{ public $data; public $next; public function __construct($data) { $this-&gt;data=$data; $this-&gt;next=null; } } class linkedList { public $firstNode; public $lastNode; public $link; public function __construct() { $this-&gt;firstNode = NULL; $this-&gt;lastNode = NULL; $this-&gt;link=NULL; } public function insertFirst($data) { $tempStore=new listNode($data); $this-&gt;firstNode=clone($tempStore); $tempStore-&gt;next=$this-&gt;link; $this-&gt;link=$tempStore; if($this-&gt;lastNode == NULL){ $this-&gt;lastNode = $this-&gt;link; } } public function insertLast($data) { if($this-&gt;firstNode==null) { $this-&gt;insertFirst($data); }else{ $tempStore=new listNode($data); $this-&gt;lastNode-&gt;next=$tempStore; print_r($this-&gt;lastNode); $this-&gt;lastNode=$tempStore; print_r($this-&gt;lastNode); } } public function makeCircular() { } } $totalNodes=5; $theList = new linkedList(); for($i=1; $i &lt;= $totalNodes; $i++) { $theList-&gt;insertLast($i); } print_r($theList); </code></pre> <p>linkedList Object ( [firstNode] => listNode Object ( [data] => 1 [next] => )</p> <pre><code>[lastNode] =&gt; listNode Object ( [data] =&gt; 5 [next] =&gt; ) [link] =&gt; listNode Object ( [data] =&gt; 1 [next] =&gt; listNode Object ( [data] =&gt; 2 [next] =&gt; listNode Object ( [data] =&gt; 3 [next] =&gt; listNode Object ( [data] =&gt; 4 [next] =&gt; listNode Object ( [data] =&gt; 5 [next] =&gt; ) ) ) ) ) </code></pre> <p>)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload