简体   繁体   English

在双链表中的指定参数之前删除项目

[英]Removing item before specified parameter in Double Linked List

I'm not sure how to link a two nodes together. 我不确定如何将两个节点链接在一起。 I understand that in order to link the first one with the third one (because i'm removing the second one), I use something like crt.next = crt.next.next but how am i supposed to do link the node that node back? 我知道为了将第一个链接到第三个链接(因为我要删除第二个链接),我使用诸如crt.next = crt.next.next之类的东西,但是我应该如何链接该节点背部?

Example: 例:

X1 <> x2 <> X3 <> x4 <> x5 I want to remove x3. X1 <> x2 <> X3 <> x4 <> x5我要删除x3。 so i link x2 to x4 by crt.next = crt.next.next I don't know how to linke x4 back to x2. 所以我通过crt.next = crt.next.next将x2链接到x4我不知道如何将x4链接回x2。

Thanks 谢谢

After you do 做完之后

crt.next = crt.next.next

you can do: 你可以做:

crt.next.prev = crt

since you want to link crt as the previous link from crt.next. 因为您要将crt链接为crt.next的上一个链接。

Linking x4 to x2 would be 将x4链接到x2将是

crt.next.next.prev=crt;

then you need to free x3 memory 那么您需要释放x3内存

free(x3);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM