我的代码有一些问题。它说str
没有属性top
..这个程序的含义是使用链表,每当我尝试输入一些值时,put
我都会遇到一些错误..
class LinkedQ(object):
def __init__(self):
self.top = None
def __str__(self):
s = ""
p = self.first
while p != None:
s = s + str(p.value)
p = p.next
return s
def put(self):
ny = Node(x)
ny.next = self.top
self.top = ny
def get(self):
x = self.top.value
self.top = self.top.next
return x
def isEmpty(self):
if self.top == None:
return True
else:
return False
class Node:
def __init__(self, x):
self.value = x
self.next = None
row = input("Write line of numbers (1 2 3 4): ")
row_pi = row.split()
for i in row_pi:
LinkedQ.put(i)