我是 python 的初学者,我在这个程序中遇到了问题:
这是 NodeList 首先:
class Node:
def __init__(self,initdata):
self.data = initdata
self.next = None
def getData(self):
return self.data
def getNext(self):
return self.next
def setData(self,newdata):
self.data = newdata
def setNext(self,newnext):
self.next = newnext
我的问题出在这个程序中:(打印)
from NodeList import Node
class StackLL:
def __init__(self):
self.head = None
def pushSLL(self,item):
temp = Node(str(item))
temp.setNext(self.head)
self.head = temp
node = self.head
print(chr(0x2510)+(chr(0x0000)*(len(item)))+chr(0x250c))
while node!=None:
stackeditem = chr(0x2502)+node.data+chr(0x2502)
print(stackeditem)
node = node.next
print(chr(0x2514)+(chr(0x2500)*(len(item)-1))+chr(0x2518))
每次我打印时,线条似乎都消失了。我尝试使用 len() 只是为了使其准确,但每次该项目添加更多字符时,它都会再次关闭。任何帮助将不胜感激。谢谢你。