Re: Shuffling a linked list
- From: "A. Farber" <Alexander.Farber@xxxxxxxxx>
- Date: 29 Dec 2006 15:01:15 -0800
Hi again,
Richard Heathfield wrote:
Just use the standard shuffling algorithm, mildly adapted for lists.
Point one of your pointers, P1, to the first unprocessed item in the list,
item I. (There are 32 - I unprocessed items.) Pick a random number in the
range 1 to 32 - I. Counting the item pointed to by P1 as 1, keep counting
along the list, using P2 to point, until you hit the random number you
generated. Swap the data at P1 with the data at P2. Now move P1 to point to
the next item on the list. Iterate until done. (When P1 is NULL - because
it fell off the end of the list - you're done.)
oops actually it is not so good idea, because
I have to run from the beginning again and again
(to find a position i).
I'll probably go for 2 lists then.
Regards
Alex
--
http://preferans.de
.
- References:
- Shuffling a linked list
- From: A. Farber
- Re: Shuffling a linked list
- From: Richard Heathfield
- Re: Shuffling a linked list
- From: A. Farber
- Shuffling a linked list
- Prev by Date: Re: division by zero mystery
- Next by Date: Re: reading BIOS dump
- Previous by thread: Re: Shuffling a linked list
- Next by thread: Re: Shuffling a linked list
- Index(es):
Relevant Pages
|