
172 Introduction to Computational Models with Python
Listing 11.3 shows two auxiliary methods in class LinkedList and these
methods are detach
head and attach. These auxiliary methods are used in the
recursive function revList. The cla ss is stored in file linklistc.py and only
the last part of the listing is shown.
Listing 11.3 Auxiliary methods in class LinkedList.
69 def detach_head(self):
70 #detach head node
71 lhead = self.head
72 lref = self.head.next
73 self.head = lref
74 lhead.next = None
75 self.numnodes -= 1
76 return lhead
77
78 def attach(self, subl2):
79 lnode = self.head
80 while lnode.next != None:
81 lnode = lnode.next
82 lnode.next = subl2