From: Simon Wright <simon@pushface.org>
Subject: Re: can't understand how to move a node of a linked list to another place on the same
Date: Fri, 19 Feb 2021 09:09:23 +0000 [thread overview]
Message-ID: <ly35xs8lvg.fsf@pushface.org> (raw)
In-Reply-To: 4e824d60-5e60-4af8-97cd-30b76ced5943n@googlegroups.com
Mehdi Saada <00120260a@gmail.com> writes:
> X means the node of place X, that I want moved before the node of
> place Y.
I don't think it does that; I think it moves it _after_. Weren't you
just having a conversation about clarity of purpose?
May I say that a simple linked list isn't a good structure if you want
to do this sort of thing to it! as you (and I) have found.
Consider a list [p q r s t] and you want to move r after s. I'm going to
use w -> x to mean that the node whose value is 'w' has Next pointing to
the node whose value is 'y'; personally I find it easier to draw the
nodes on paper, it's hard work typing the equivalent. YMMV.
Using your original naming, Before_A -> q, Before_B -> r.
procedure Insertion_A_On_Place_B (Before_A, Before_B: in T_List) is
A: constant T_List := Before_A.Next;
-- r
B: constant T_List := Before_B.Next;
-- s
begin
Before_A.Next := A.Next;
-- q -> s
A.Next := B;
-- r -> s (no change!)
Before_B.Next := A;
-- r -> r
end Insertion_A_On_Place_B;
and the list is now [p q s t], with r left dangling and pointing to
itself.
next prev parent reply other threads:[~2021-02-19 9:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-18 1:51 can't understand how to move a node of a linked list to another place on the same Mehdi Saada
[not found] ` <1b206764-967c-4b1b-af9c-61a0cd0750fcn@googlegroups.com>
2021-02-18 7:06 ` Gautier write-only address
2021-02-18 12:54 ` Mehdi Saada
2021-02-18 15:09 ` Jeffrey R. Carter
2021-02-18 20:56 ` Simon Wright
2021-02-18 22:38 ` Mehdi Saada
2021-02-19 9:09 ` Simon Wright [this message]
2021-02-19 14:13 ` Mehdi Saada
2021-02-19 18:56 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox