Implement a linked list and I expect output to be 0, -1, -2, -3, ... etc.
, but it is -98, -98, -98, -98, ... etc.
, wondering what is wrong in my code? Thanks.
MAXSIZE = 100
freeListHead = None
class StackNode:
def __init__(self, value, nextNode):
self.value = value
self.nextNode = nextNode
if __name__ == "__main__":
# initialization for nodes and link them to be a free list
nodes=[StackNode(-1, None)] * MAXSIZE
freeListHead = nodes[0]
for i in range(0, len(nodes)-1):
nodes[i].nextNode = nodes[i+1]
nodes[i].value = -i
for node in nodes:
# output -98, -98, -98, -98, ... etc.
# exepcted output, 0, -1, -2, -3, ... etc.
print node.value