@@ -21,12 +21,12 @@ public function insert(string $data = NULL) {
2121        $ newNodenew  ListNode ($ data
2222        if  ($ this _firstNode  === NULL ) {
2323            $ this _firstNode  = &$ newNode
24-             $ this _lastNode  = $ newNode
24+             $ this _lastNode  = & $ newNode
2525        } else  {
2626            $ currentNode$ this _lastNode ;
2727            $ currentNodenext  = $ newNode
2828            $ newNodeprev  = $ currentNode
29-             $ this _lastNode  = $ newNode
29+             $ this _lastNode  = & $ newNode
3030        }
3131        $ this _totalNode ++;
3232        return  TRUE ;
@@ -36,10 +36,12 @@ public function insertAtFirst(string $data = NULL) {
3636        $ newNodenew  ListNode ($ data
3737        if  ($ this _firstNode  === NULL ) {
3838            $ this _firstNode  = &$ newNode
39+             $ this _lastNode  = &$ newNode
3940        } else  {
4041            $ currentFirstNode$ this _firstNode ;
4142            $ this _firstNode  = &$ newNode
4243            $ newNodenext  = $ currentFirstNode
44+             $ this _lastNode  = &$ currentFirstNode
4345        }
4446        $ this _totalNode ++;
4547        return  TRUE ;
@@ -73,6 +75,7 @@ public function insertBefore(string $data = NULL, string $query = NULL) {
7375                }
7476                $ previous$ currentNode
7577                $ currentNode$ currentNodenext ;
78+                 
7679            }
7780        }
7881    }
@@ -90,6 +93,11 @@ public function insertAfter(string $data = NULL, string $query = NULL) {
9093                    }
9194                    $ currentNodenext  = $ newNode
9295                    $ this _totalNode ++;
96+                     
97+                     if ($ currentNode$ this _lastNode ) {
98+                         $ this _lastNode  = &$ newNode
99+                     }
100+                     
93101                    break ;
94102                }
95103                $ currentNode$ currentNodenext ;
@@ -104,6 +112,7 @@ public function deleteFirst() {
104112                $ this _firstNode  = $ this _firstNode ->next ;
105113            } else  {
106114                $ this _firstNode  = NULL ;
115+                 $ this _lastNode  = NULL ;
107116            }
108117            $ this _totalNode --;
109118            return  TRUE ;
@@ -125,6 +134,7 @@ public function deleteLast() {
125134                }
126135
127136                $ previousNodenext  = NULL ;
137+                 $ this _lastNode  = &$ previousNode
128138                $ this _totalNode --;
129139                return  TRUE ;
130140            }
@@ -143,6 +153,10 @@ public function delete(string $query = NULL) {
143153                    } else  {
144154                        $ previousnext  = $ currentNodenext ;
145155                    }
156+                     
157+                     if ($ currentNode$ this _lastNode ) {
158+                         $ this _lastNode  = &$ previous
159+                     }
146160
147161                    $ this _totalNode --;
148162                    break ;
0 commit comments