小魚要學數據結構(基於python)—Day6有序表與線性結構小結

數據結構(北大公開課)

線性結構

有序表

1、有序表知識結構
有序表知識腦圖
2、有序表算法分析
有序表算法分析
3、有序表實現

#有序表
class OrderedList:
    def __init__(self):
        self.head=None
    def search(self,item):
        current=self.head
        found=False
        stop=False
        while current!=None and not found and not stop:
            if current.getData()==item:
                found=True
            else:
                if current.getData()>item:
                    stop=True
                else:
                    current=current.getNext()
        return found
    def add(self,item):
        current=self.head
        previous=None
        stop=False
        while current != None and not stop:
            if current.getData()>item:#發現插入位置
                stop=True
            else:
                previous=current
                current=current.getNext()
        temp=Node(item)
        if previous==None:#插在表頭
            temp.setNext(self.head)
            self.head=temp
        else:
            temp.setNext(current)
            previous.setNext(temp)

線性結構小結

線性結構小結

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章