用户工具

站点工具


链表

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
后一修订版
前一修订版
链表 [2025/12/03 04:43]
1.92.215.116 已恢复为旧版 (2025/11/23 00:37)
链表 [2026/01/27 16:27] (当前版本)
116.204.64.97 已恢复为旧版 (2025/12/07 15:11)
行 1: 行 1:
  
- +
   定义链表    定义链表 
-  
   class ListNode {    class ListNode { 
-    public $val = NULL;  +     public $val = NULL;  
-    public $next = NULL; +     public $next = NULL; 
    function __construct($val = 0, $next = null) {    function __construct($val = 0, $next = null) {
            $this->val = $val;            $this->val = $val;
行 11: 行 10:
       }       }
   }   }
-  +    
 +    
   class LinkList {    class LinkList { 
-     
      public $next=null;      public $next=null;
-      
      public function insert($val = NULL) {       public function insert($val = NULL) { 
-       $newNode = new ListNode($val);  +        $newNode = new ListNode($val); 
         if ($this->next === NULL) {                    if ($this->next === NULL) {           
             $this->next = $newNode;                          $this->next = $newNode;             
行 25: 行 23:
             while ($currentNode->next !== NULL) {              while ($currentNode->next !== NULL) { 
                 $currentNode = $currentNode->next;                  $currentNode = $currentNode->next; 
-            +         
             $currentNode->next = $newNode;              $currentNode->next = $newNode; 
         }          } 
-  +    
-    }  +   public function insert_arr($arr = array() ) { 
- +
- +
-  public function insert_arr($arr = array() ) { +
        foreach($arr as $val){        foreach($arr as $val){
           $this->insert($val);             $this->insert($val);  
        }        }
    
-    +     
-    public function display() {  +  public function display() {  
-      echo "当前链表的是: <br/>"; +  echo "当前链表的是: <br/>"; 
         $currentNode = $this->next;          $currentNode = $this->next; 
         while ($currentNode !== NULL) {          while ($currentNode !== NULL) { 
/home/minxuanbm4ipnyxlu3ann/wwwroot/dokuwiki/data/attic/链表.1764708221.txt.gz · 最后更改: 2025/12/03 04:43 由 1.92.215.116