def insert(i,elem): #在位置i处插入结点
pos=0
if i<1:
raise IndexError
p = self.head
while p.next is not None:
q=p
#补充
if pos ==i:
#补充
return
return IndexError

Python数据结构单链表求解
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- chuifengde 2021-11-09 11:26关注
pos +=1
#--------------
p.next =elem
elem.next=q.next
p=p.next本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用