{"id":762,"date":"2017-03-01T12:06:38","date_gmt":"2017-03-01T20:06:38","guid":{"rendered":"http:\/\/www.tech.dimprash.com\/?p=762"},"modified":"2017-03-01T12:06:38","modified_gmt":"2017-03-01T20:06:38","slug":"implement-a-linked-list-in-php","status":"publish","type":"post","link":"http:\/\/www.tech.dimprash.com\/?p=762","title":{"rendered":"Implement a Linked List in PHP"},"content":{"rendered":"<pre>\r\nclass Node {\r\n  public $val;\r\n  public $next;\r\n\r\n  function __construct($val) {\r\n      $this->val = $val;\r\n      $this->next = $null;\r\n  }\r\n}\r\n\r\nclass LinkedList {\r\n  public $head;\r\n\r\n  function __construct() {\r\n      $this->head = null;\r\n  }\r\n\r\n  function InsertNode($val) {\r\n      $node = new Node($val);\r\n      if ($this->head) {\r\n          $current = $this->head;\r\n          while ($current != null) {\r\n              $prev = $current;\r\n              $current = $current->next;\r\n          }\r\n          $prev->next = $node;\r\n      } else {\r\n          $this->head = $node;\r\n      }\r\n  }\r\n\r\n  function PrintAll() {\r\n      $current = $this->head;\r\n      while ($current != null) {\r\n          print $current->val . \"\\n\";\r\n          $current = $current->next;\r\n      }\r\n  }\r\n}\r\n\r\n$linkedList = new LinkedList();\r\n$linkedList->InsertNode(1);\r\n$linkedList->InsertNode(3);\r\n$linkedList->InsertNode(2);\r\n\r\n$linkedList->PrintAll();\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>class Node { public $val; public $next; function __construct($val) { $this->val = $val; $this->next = $null; } } class LinkedList { public $head; function __construct() { $this->head = null; } function InsertNode($val) { $node = new Node($val); if ($this->head) { $current = $this->head; while ($current != null) { $prev = $current; $current = $current->next; } &hellip; <a href=\"http:\/\/www.tech.dimprash.com\/?p=762\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Implement a Linked List in PHP<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-762","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/762","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=762"}],"version-history":[{"count":1,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/762\/revisions"}],"predecessor-version":[{"id":763,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/762\/revisions\/763"}],"wp:attachment":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=762"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}