First of all, you're doing your class kind of wrong. Every class method has a
So instead of:
Edited to add:
You don't create class instances ("instantiate") a class with
You create a class instance with:
self
argument with which you reference variables and methods within that class.So instead of:
head = None class Linked: def foo(): global head head = Node()You should have this:
class Linked: def __init__(self): """This is the class constructor. You can initialize "member variables" here. """ self.head = None def AddBookToFront(self, val): # you can reference head with self.head tmp = self.head self.head = Node() self.head.next = tmpThen to reference other methods within the same class, you also use self:
class Linked: def __init__(self): """This is the class constructor. You can initialize "member variables" here. """ self.head = None def mergeSort(self): # do stuff... self.divideList(self.head)In any event you can't call divideList because it's part of the LinkedList class. It might work if you call
LinkedList.divideList(head)
but you should really consider making the other changes I mentioned because that's the correct way to write classes in Python.Edited to add:
You don't create class instances ("instantiate") a class with
ll = LinkedList
; that just creates an alias or another way to refer to LinkedList.You create a class instance with:
ll = LinkedList()
which invokes the constructor.