Convert a String to a Singly Linked List | Java program to 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 GFG { static class node { char data ; node next ; } ; static node add ( char data ) { node newnode = new node ( ) ; newnode . data = data ; newnode . next = null ; return newnode ; } static node string_to_SLL ( String text , node head ) { head = add ( text . charAt ( 0 ) ) ; node curr = head ; for ( int i = 1 ; i < text . length ( ) ; i ++ ) { curr . next = add ( text . charAt ( i ) ) ; curr = curr . next ; } return head ; } static void print ( node head ) { node curr = head ; while ( curr != null ) { System . out . print ( curr . data + " ▁ - > ▁ " ) ; curr = curr . next ; } } public static void main ( String [ ] args ) { String text = " GEEKS " ; node head = null ; head = string_to_SLL ( text , head ) ; print ( head ) ; } }