python - Understanding control flow in traversing through list -


Here I have a class that uses a node and a function that prints the node in reverse order:

  Category LLNode (object): def __init __ (self, data): '' '(LLNode, object) - & gt; None create a new node to hold '' 'type data self.data = data self.link = any def __str __ (self): return str (self.data) def reverse_list (L): If no one Returns head = L Tail = Head.link reverse_list (tail) print (head, end = '') list1 = LLNode (1) list1.link = LLNode (2) print (reverse_list (list1))  < / Pre> 

I do not understand that when the print statement runs, because is placed before the reverse_list (tail) , I think That look it I have been charged that if I change those two lines then the program will print the sequence in the link list, which I understand. How to reverse it after inserting print Prints in? I do not understand the flow here

Because print ing After a recursive call, this happens when the calling function returns control, back up is a simple example here:

  & gt; & Gt; & Gt; DEF RICKUR (X): print ("going down ({0})". Format (x)) if not x: print ("bottom hit") print ("Coming ({{}}" Format (x) Returns no recurrence (x-1) print ("Coming ({{}}". Format (x))> gt; & Gt; & Gt; Repeat (2) Going Down (2). Going down (1) are going down (0). The hit is coming down (0). Coming (1) Coming (2)    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -