链表的操作

from collections import deque # 这里的deque源码在哪看,想找deque.remove()函数有没有返回值


linkedlist = deque() # 队列的实现
linkedlist.append(1)
linkedlist.append(2)
linkedlist.append(3)
print(linkedlist)
# 插入元素
linkedlist.insert(1,'4')
print(linkedlist)
# a = linkedlist(2) # 括号一般都是迭代的么 object is not callable
# 查找元素
a = linkedlist[2]
print(a,linkedlist[2])
# 搜索元素的索引
print(linkedlist.index(3))
# 更新元素
linkedlist[2] = 3
print(linkedlist)
# 删除元素
print(linkedlist.remove(3)) # None;看来deque.remove()函数没返回值
print(linkedlist) # deque([1, '4', 3])
linkedlist.remove(1)
print(linkedlist) # deque(['4', 3])
length = len(linkedlist)
print(length) # 2
posted @ 2021-09-23 19:59  索匣  阅读(23)  评论(0编辑  收藏  举报