I'm having troubles doing a shuffle for a linked list. I've tried numerous ways to make this work but I'm having issues. What I believe to be the problem with it now is that in the for loop when I make the next and previous portions of the list Null since its pointing to the actual head list it also makes it null then once it iterates through again its now set to null and breaks. How can I go about correcting this? Do I need to have more copies of the list? Or is there a completely better way of doing this?
My bad. Whats suppose to happen which I didn't realize until now is that you split the list in half and you now have two lists. Left one and a right one. You take the bottom card off the left one and put it at the bottom of a new list, then you take the card off the bottom of the right one and add it on top of the new list.
So if you have left list = 1, 2 , 3 and right list = 4 , 5 ,6 when you shuffle the list they turn into.
Anyway, abstraction could help. Make logic that operates with lists rather than nodes. Then implement the necessary list operations.
1. You have list A. Create empty lists B and C.
2. Move second half of A into C and first half into B. A is now empty.
3. Append(move) head of B into A. Append(move) head of C into A.
4. Repeat 3 until B and C are empty.
Do not assume that input (A) has exactly 52 cards.
Steps 2 and 3 split list in two. Step 3 is special version, because it separates only the first node. Step 3 appends a node to a list.
PS. Please explain your line 6. What is that card? A joker?
I can get them into two separate lists and start setting them into a new list. I can get the first two cards shuffled right but as I'm going through it the lists get jumbled. I just cant understand this stuff.