Re: Shuffling a linked list
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Fri, 29 Dec 2006 12:05:12 -0500
"A. Farber" <Alexander.Farber@xxxxxxxxx> wrote in message
news:1167407792.061885.180820@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello,
I have a doubly-linked list of 32 playing cards, which I'd like to
randomly and evenly (!) shuffle.
(For several reasons I'm not using an array, which I could go
through once, keeping swapping cards at random positions.)
I have a list head with 2 pointers - to the very 1st and to the
last elements and I have 2 macros to insert an element at the
"head" or at the "tail".
Does anybody please have a good algorithm for me?
You have 2 lists: an input list and an output list. At the start of the
algorithm, your input list is of length 32, and your output list is of
length 0. At the end of the algorithm, your input list will be length 0 and
your output list will be length 32.
while(there are still cards in the input list) {
choose a card randomly from the input list.
Move that card to the tail of the output list.
}
- Oliver
.
- Follow-Ups:
- Re: Shuffling a linked list
- From: CBFalconer
- Re: Shuffling a linked list
- From: A. Farber
- Re: Shuffling a linked list
- References:
- Shuffling a linked list
- From: A. Farber
- Shuffling a linked list
- Prev by Date: Re: help in understanding this problem (beginner)
- Next by Date: Re: Shuffling a linked list
- Previous by thread: Shuffling a linked list
- Next by thread: Re: Shuffling a linked list
- Index(es):
Relevant Pages
|
|