Print List title description from tail to head
Enter a list to print the values of each node of the list from the end of the head.
Implementation code
/* function ListNode (x) { this.val = x; This.next = null;} */ function Printlistfromtailtohead (head) { var res=[]; while (head) { res.unshift (head.val); Head=head.next; } return Res;}
Related knowledge
Create a linked list and implement the INSERT, delete, add method
functionLinkedList () {varNode=function(val) { This. val=Val; This. next=NULL; } varLength=0; varHead=NULL; This. append=function(val) {varNode=NewNode (val), current; if(head==NULL) {Head=node; }Else{ Current=Head; while(current.next) { current=Current.next; } Current.next=node; } length++; }; This. removeat=function(POS) {if(Pos>-1 && pos<length) { varCurrent=Head, Previous, index=0; if(pos===0) {Head=Current.next; }Else{ while(index++<POS) {Previous=Current ; Current=Current.next; } length--; Previous.next=Current.next; } }Else{ return NULL; } }; This. insertat=function(pos,val) {if(Pos>=0 && Pos <=length) { varNode=NewNode (), current=Head, Previous, index=0; if(pos===0) {Head=node; }Else{ while(index++<POS) {Previous=Current ; Current=Current.next; } Node.next=Current ; Previous.next=node; } length++; return true; }Else{ return NULL; } };}
-javascript (3) Print a list from the end of the head