1
這是我的代碼,每次我調用插入函數時,我都會得到一個輸出:<__main__.CircularList object at 0x10597fd68>
。 我想通過調用for循環來使用插入函數來實際創建循環鏈表。使用循環鏈接列表插入功能
class Link (object):
def __init__ (self, data, next = None):
self.data = data
self.next = next
class CircularList(object):
def __init__(self):
self.first = None
# Insert an element in the list
def insert (self, item):
newLink = Link (item)
current = self.first
if (current == None):
self.first = newLink
return
while (current.next != None):
current = current.next
current.next = newLink
newLink.next = self.first
輸出仍然現身在<__ __主要對象CircularList在0x10592dd68>。我在這樣的主函數中調用它:Clist = CircularList() for i in range(1,int(num)): Clist.insert(i) – 2015-04-05 23:24:13
@franklowe:顯然,你沒有覆蓋打印功能和'CircularList'的實例保持不變,無論你如何修改它。你應該問如何**打印**列表,而不是如何**插入項目**如果這是目標。 – 2015-04-05 23:25:53
我給出了不同的值,我讀了,我應該做的循環列表節點的長度。 – 2015-04-05 23:29:00