[英]Function to move elements to the end of a doubly linked list up to a certain index
For example, given a double linked list with {4, 5, 6, 7}, and an index 2, the function should result in the node being {6, 7, 4, 5}. 例如,给定带有{4,5,6,7}和索引2的双链表,该函数应导致节点为{6,7,4,5}。 Is it possible to do this without creating a temp node?
是否可以在不创建临时节点的情况下执行此操作?
My implementation has a head and tail, both set to null. 我的实现有一个头和尾,都设置为null。 Nodes can be accessed with next/previous.
可以使用下一个/上一个访问节点。
Any help would be greatly appreciated! 任何帮助将不胜感激!
I'm not sure about how you implemented it. 我不确定您是如何实现的。 But this is how I would do it as a pseudocode.
但这就是我将其作为伪代码执行的方式。
tail.prev.next = head.next
head.next.prev = tail.prev
tail.prev = head.next
head.next = head.next.next
tail.prev.next = tail
head.next.prev = head
1) Head and Tail nodes are present and they are linked to the first node and the last node, respectively. 1)存在头和尾节点,它们分别链接到第一个节点和最后一个节点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.