I'm working on the problem of print a linked list reversely without destruction. I'm wondering if any other better ideas, in terms of both time complexity improvement and space complexity improvement. I also welcome for code bugs and code style advice.
class LinkedListNode:
def __init__(self, value, nextNode):
self.value = value
self.nextNode = nextNode
def print_reverse(self):
if not self.nextNode:
print self.value
return
else:
self.nextNode.print_reverse()
print self.value
if __name__ == "__main__":
head = LinkedListNode('a', LinkedListNode('b', LinkedListNode('c', LinkedListNode('d', None))))
head.print_reverse()