I've created a linked list class in Python, but I'm not sure how to enforce only passing Node
objects into the insert
routine.
# linked list in Python
class Node:
"""linked list node"""
def __init__(self, data):
self.next = None
self.data = data
def insert(self, n):
n.next = self.next
self.next = n
return n
def showall(self):
print self.data
if self.next != None:
self.next.showall()
ll = Node("one")
ll.insert(Node("two")).insert(Node("three"))
ll.showall()
@singledispatch
. – Morwenn Apr 1 '14 at 8:36