Reverse each word in a linked list node | Linked list Node ure ; Function to create newNode in a linked list ; reverse each node data ; iterate each node and call reverse_word for each node data ; printing linked list ; Driver program
class Node { constructor ( ) { this . c = " " ; this . next = null ; } } ; function newNode ( c ) { var temp = new Node ( ) ; temp . c = c ; temp . next = null ; return temp ; } function reverse_word ( str ) { var s = " " ; for ( var i = 0 ; i < str . length ; i ++ ) s = str [ i ] + s ; return s ; } function reverse ( head ) { var ptr = head ; while ( ptr != null ) { ptr . c = reverse_word ( ptr . c ) ; ptr = ptr . next ; } return head ; } function printList ( head ) { while ( head != null ) { document . write ( head . c + " " ) ; head = head . next ; } } var head = newNode ( " " ) ; head . next = newNode ( " " ) ; head . next . next = newNode ( " " ) ; head . next . next . next = newNode ( " " ) ; head . next . next . next . next = newNode ( " " ) ; head . next . next . next . next . next = newNode ( " " ) ; head . next . next . next . next . next . next = newNode ( " " ) ; document . write ( " " ) ; printList ( head ) ; head = reverse ( head ) ; document . write ( " " ) ; printList ( head ) ;