From: Mehdi Saada <00120260a@gmail.com>
Subject: Re: can't understand how to move a node of a linked list to another place on the same
Date: Thu, 18 Feb 2021 04:54:51 -0800 (PST) [thread overview]
Message-ID: <f3d5e634-39e4-4c60-8f28-bb111df8391dn@googlegroups.com> (raw)
In-Reply-To: <84c3e8ee-e4e9-4402-8da6-e43a44eca66bn@googlegroups.com>
Le jeudi 18 février 2021 à 08:06:57 UTC+1, gautier...@hotmail.com a écrit :
> > No, I'll run it on paper first, please don't bother yet.
> That's actually the fun part with linked lists.
> That's actually the fun part with linked lists.
I hate that to no end.
I did put up quite the effort so non-ashamedly I beg for help.
Here's it running on paper. Of course it's wrong 'cause the actual result is still A disappearing.
procedure insertion_X_on_place_Y (Before_X, Before_Y: in t_List) is
A: constant t_List := Before_X.next;
Y: constant t_List := Before_Y.next;
Begin
Before_X.next := Before_X.next.next;
X.next := Y;
Before_Y.next := X;
end insertion_X_on_place_Y;
Before running:
X (x)->(x+1)->..
Y (y)->(y+1)->..
Before_X (x-1)->(x)->(x+1)...->(Y-1)->(Y)->(y+1)..
Before_X.next (x)->(x+1)...->(Y-1)->(Y)->(y+1)..
Before_Y (Y-1)->(Y)->(y+1)..
Before_Y.next (Y)->(y+1)..
But: I want (x-1)->(x+1)...->(Y-1)->(x)-> (Y)->(y+1)..
Before_X.next := X.next;
X (x)->(x+1)->..
Y (y)->(y+1)->..
Before_X (x-1)-> (x+1)...->(Y-1)->(Y)->(y+1)..
Before_X.next (x+1)...->(Y-1)->(Y)->(y+1)..
Before_Y (Y-1)->(Y)->(y+1)..
Before_Y.next (Y)->(y+1)..
X.next := Y;
X (x)->(y)->(y+1)->..
Y (y)->(y+1)->..
Before_X (x-1)-> (x+1)...->(Y-1)->(Y)->(y+1)..
Before_X.next (x+1)...->(Y-1)->(Y)->(y+1)..
Before_Y (Y-1)->(Y)->(y+1)..
Before_Y.next (Y)->(y+1)..
Before_Y.next := X;
X (x)->(y)->(y+1)->..
Y (y)->(y+1)->..
Before_X (x-1)-> (x+1)...->(Y-1)->(x)->(y)->(y+1)->..
Before_X.next (x+1)...->(Y-1)->(x)->(y)->(y+1)->..
Before_Y (Y-1)->(x)->(y)->(y+1)->..
Before_Y.next (x)->(y)->(y+1)->..
It SHOULD be ok.
then I display it:
insertion_A_on_place_b(List, List.next);
ITERATOR := List;
while ITERATOR /= null loop
Put(ITERATOR.value'Image & ' ');
ITERATOR := ITERATOR.next;
end loop;
'1'
'3'
'4'
'5'
PLEASE HELP.
next prev parent reply other threads:[~2021-02-18 12:54 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 [this message]
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
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