首頁>技術>

順序儲存

a=[None for i in range(100)]cur=-1def append(v):    global cur    if cur<99:        cur=cur+1        a[cur]=v    def insert(pos,v):    global cur    global a    if pos<=cur and cur<99:        for i in range(cur+1,pos,-1):            a[i]=a[i-1]        a[pos]=v    def delete(pos):    global cur    global a    if pos<=cur:        for i in range(pos,cur):            a[i]=a[i+1]        a[cur]=None        cur=cur-1def print_item(pos):    global cur    global a    if pos<=cur:        print(a[pos])        def print_all():    global a    for e in a :        if e:            print(e)append(23)append(45)delete(1)print_all()

使用列表方法實現

a=[i for i in range(10)]print(a[5])print(a)a.insert(6,100)del(a[6])

15
最新評論
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • SpringBoot Web專案打包獨立Jar(3)