11# Program to print the elements of a linked list in reverse 
2- 
32from  typing  import  List 
43
54class  Node :
@@ -20,22 +19,18 @@ def __repr__(self):
2019
2120def  make_linked_list (elements_list : List ):
2221    """Creates a Linked List from the elements of the given sequence 
23-     (list/tuple) and returns the head of the Linked List.""" 
24-     """ 
25-     >>> make_linked_list() 
26-     Traceback (most recent call last): 
27-         ... 
28-     Exception: The Elements List is empty 
22+     (list/tuple) and returns the head of the Linked List. 
23+ 
2924    >>> make_linked_list([]) 
3025    Traceback (most recent call last): 
3126        ... 
3227    Exception: The Elements List is empty 
3328    >>> make_linked_list([7]) 
34-     ' <7> ---> <END>'  
29+     <7> ---> <END> 
3530    >>> make_linked_list(['abc']) 
36-     ' <abc> ---> <END>'  
31+     <abc> ---> <END> 
3732    >>> make_linked_list([7, 25]) 
38-     ' <7> ---> <25> ---> <END>'  
33+     <7> ---> <25> ---> <END> 
3934    """ 
4035
4136    # if elements_list is empty 
@@ -55,12 +50,8 @@ def make_linked_list(elements_list: List):
5550
5651
5752def  print_reverse (head_node : Node ):
58-     """Prints the elements of the given Linked List in reverse order""" 
59-     """ 
60-     >>> print_reverse() 
61-     None 
53+     """Prints the elements of the given Linked List in reverse order 
6254    >>> print_reverse([]) 
63-     None 
6455    """ 
6556
6657    # If reached end of the List 
@@ -72,9 +63,27 @@ def print_reverse(head_node: Node):
7263        print (head_node .data )
7364
7465
75- list_data  =  [14 , 52 , 14 , 12 , 43 ]
76- linked_list  =  make_linked_list (list_data )
77- print ("Linked List:" )
78- print (linked_list )
79- print ("Elements in Reverse:" )
80- print_reverse (linked_list )
66+ def  test_print_reverse_output ():
67+     test_list_data  =  [69 , 88 , 73 ]
68+     linked_list  =  make_linked_list (test_list_data )
69+ 
70+     print_reverse (linked_list )
71+ 
72+ def  main ():
73+     """ 
74+     >>> test_print_reverse_output() 
75+     73 
76+     88 
77+     69 
78+     """ 
79+     list_data  =  [14 , 52 , 14 , 12 , 43 ]
80+     linked_list  =  make_linked_list (list_data )
81+     print ("Linked List:" )
82+     print (linked_list )
83+     print ("Elements in Reverse:" )
84+     print_reverse (linked_list )
85+ 
86+ 
87+ if  __name__  ==  "__main__" :
88+     main ()
89+ 
0 commit comments