Well your current function will need just a little correction and should be working fine.
1 2 3 4 5 6
|
Card* DeckSplit(Card* head, Card* tail)// this might leak your memory
{
for (int i = 0; i < Split; i++)
head = head->next;
head = tail; return(head);
}
|
Let me give you an idea on how to keep track of all your nodes
1. Iterate to your point of split, "note it will be handy to create to temporal pointers"
temp_tail which will point to the point of split and temp_head to point to the point of split +1
2. reset temp_tail next pointer to nullptr and similarly reset temp_head pointer previous to nullptr.
Now we got two separated parts.
3. let's join them.
Reset the initial head previous pointer to point to the initial tail, similarly reset the tail next pointer to
point to the head. Wow we just rejoined them as you wished hehe.
4. Now that we got our list up again we need to reset the head and tail pointers so that it will be similar to
our initial list. Here just set the head pointer equal to temp_head and tail equal to temp_tail .... that's it
our list is good to go.