只给出一个指向要在单个链表中删除的节点的指针,你如何删除它? [英] Given only a pointer to a node to be deleted in a singly linked list, how do u delete it?

查看:193
本文介绍了只给出一个指向要在单个链表中删除的节点的指针,你如何删除它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone,


解决方案是将数据从下一个节点复制到这个

节点并删除下一个节点! br />
1.但是如果要删除的节点是最后一个节点。那么我们应该怎么做?b $ b呢?

2.如果列表是头节点?

3如果列表是循环的,那么我们所有的条件是什么需要检查?


谢谢,

kaka

解决方案

< blockquote> ac******@gmail.com 说:


Hello Everyone,


解决方案是将数据从下一个节点复制到这个

节点并删除下一个节点! 。



不,解决方案是重新设计删除例程的接口

,以便您获得足够的信息以便启用你要这么做才能完成工作。


-

Richard Heathfield

" Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名, - www。


4月14日,上午10:38,ac .C .... @ gmail.com" < ac.c .... @ gmail.comwrote:


Hello everyone,


解决方法是将数据从下一个节点复制到此

节点并删除下一个节点!



不一定。您可以标记节点以供将来删除,然后

检查下一个节点是否先前已标记并删除该节点,因为

您有指向它的指针。


1.但是如果要删除的节点是最后一个节点。那我们应该怎么做?b $ b呢?



只需标记即可。


2.如果列表是Head节点?



因为你有指向它的指针,你可以立即删除它。


3如果清单是循环然后我们需要检查的所有条件?



您需要检查头节点是否是下一个节点并相应地调整它。


希望这会有所帮助.... karl m


4月14日上午10点38分,ac.c .... @ gmail.com" < ac.c .... @ gmail.comwrote:


Hello everyone,


解决方法是将数据从下一个节点复制到这个

节点并删除下一个节点!

1.但是如果要删除的节点是最后一个节点。那我们应该怎么做?b $ b呢?



如果你使用一个空的塞子在列表末尾的节点,你会发现
永远不会得到最后一个删除节点,你的解决方案工作正常。


2.如果列表是头节点?



设置一个新头并将其删除。


希望这会有所帮助,更多..... karl m


Hello Everyone,

The solution to this is to copy the data from the next node into this
node and delete the next node!.
1. But if the node to be deleted is the last node. Then what should we
do ?
2. If the list is Head node?
3 If the list is circular then what all conditions we need to check?

Thanks,
kaka

解决方案

ac******@gmail.com said:

Hello Everyone,

The solution to this is to copy the data from the next node into this
node and delete the next node!.

No, the solution is to re-design the interface to the deletion routine
so that you get sufficient information supplied to you to enable you to
do the job properly.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


On Apr 14, 10:38 am, "ac.c....@gmail.com" <ac.c....@gmail.comwrote:

Hello Everyone,

The solution to this is to copy the data from the next node into this
node and delete the next node!.

Not necessarily. You could mark the node for future deletion and then
check if the next node was marked previously and delete that one since
you have the pointer to it.

1. But if the node to be deleted is the last node. Then what should we
do ?

Just mark it.

2. If the list is Head node?

Since you have the pointer to it, you can delete it immediately.

3 If the list is circular then what all conditions we need to check?

You need to check if the head node is the next node and adjust it
accordingly.

Hope this helps....karl m


On Apr 14, 10:38 am, "ac.c....@gmail.com" <ac.c....@gmail.comwrote:

Hello Everyone,

The solution to this is to copy the data from the next node into this
node and delete the next node!.
1. But if the node to be deleted is the last node. Then what should we
do ?

If you use an empty "stopper" node at the end of your list, you''ll
never get the "last" node for deletion and your solution works fine.

2. If the list is Head node?

Set a new head and delete it.

Hope this helps, more..... karl m


这篇关于只给出一个指向要在单个链表中删除的节点的指针,你如何删除它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆