我正在尝试编写我自己的切片概念实现,它应该适用于我自己的实现(我写的)单链表,但经过一整天的尝试,我可以说我什么都没有,每一个我写的东西根本不起作用(这就是为什么我没有发布代码), 当然它是一个获取列表,起始位置,停止位置和步骤的函数,它应该与切片相同(包括负位置和步骤),任何想法如何开始?或片的一些源代码?
代码(糟糕的尝试):
if start is None:
start = sll.head
if stop is None and dire is False:
stop = start
start = sll.head
re_list = List()
pointer = Node(start.get_data())
list_head = pointer
if start is stop:
re_list.add_first(pointer.get_data())
while start is not None and start is not stop:
for i in range(abs(step)):
start = start.get_next()
if start is None or start is stop:
break
if dire is True and start is not None and start is not stop:
pointer.set_next(Node(start.get_data()))
pointer = pointer.get_next()
elif dire is False:
re_list.add_first(start.get_data())
if dire is True:
re_list.head = list_head
elif dire is False:
re_list.head.set_next(pointer)
return re_list
谢谢