Convert a String to a Singly Linked List | Structure for a Singly Linked List ; Function to add a new node to the Linked List ; Function to convert the string to Linked List . ; curr pointer points to the current node where the insertion should take place ; Function to print the data present in all the nodes ; Driver code
class node { constructor ( ) { this . data = ' ' ; this . next = null ; } } function add ( data ) { let newnode = new node ( ) ; newnode . data = data ; newnode . next = null ; return newnode ; } function string_to_SLL ( text , head ) { head = add ( text [ 0 ] ) ; let curr = head ; for ( let i = 1 ; i < text . length ; i ++ ) { curr . next = add ( text [ i ] ) ; curr = curr . next ; } return head ; } function print ( head ) { let curr = head ; while ( curr != null ) { document . write ( curr . data + " " ) ; curr = curr . next ; } } let text = " " ; let head = null ; head = string_to_SLL ( text , head ) ; print ( head ) ;