Convert a String to a Singly Linked List | Structure for a Singly Linked List ; Function to add a 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 : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT data = None NEW_LINE next = None NEW_LINE DEDENT DEDENT def add ( data ) : NEW_LINE INDENT newnode = node ( ) NEW_LINE newnode . data = data NEW_LINE newnode . next = None NEW_LINE return newnode NEW_LINE DEDENT def string_to_SLL ( text , head ) : NEW_LINE INDENT head = add ( text [ 0 ] ) NEW_LINE curr = head NEW_LINE for i in range ( len ( text ) - 1 ) : NEW_LINE INDENT curr . next = add ( text [ i + 1 ] ) NEW_LINE curr = curr . next NEW_LINE DEDENT return head NEW_LINE DEDENT def print_ ( head ) : NEW_LINE INDENT curr = head NEW_LINE while ( curr != None ) : NEW_LINE INDENT print ( ( curr . data ) , end = " ▁ - ▁ > ▁ " ) NEW_LINE curr = curr . next NEW_LINE DEDENT DEDENT text = " GEEKS " NEW_LINE head = None NEW_LINE head = string_to_SLL ( text , head ) NEW_LINE print_ ( head ) NEW_LINE