想說之後是用C學,那就不要用C了
學習的網站
學習的網站
class Node: def __init__(self,data=None): #建構要用到的物件初始化 self.data = data #儲存資料物件 self.next =None #儲存下個物件(預設為空) return class SLinkList: #單向串列 def __init__(self): self.head = None #頭值初始化為空 def listprint(self): #印出串列值 printval =self.head #宣告印出值 while printval is not None: #當值不為空時印出值 print(printval.data) printval = printval.next #換下個印出值 def AtBegining(self,newdata): #開始的值 NewNode = Node(newdata) NewNode.next = self.head #將新節點的下一個值更新為現有節點 self.head = NewNode list = SLinkList() list.head =Node("爆") e2 = Node("氣") e3 = Node("流") list.head.next = e2 e2.next = e3 list.AtBegining("星") list.listprint() |