I cant think of a way somebody would implement this in more than O(n). The simplest way you can think of is to copy values alternately from each list until one list ends and append the remainder of the other list.. and this will be dont is O(N). what am I missing here?
What do you mean Constant space, the new shuffled list should be in the same space as A and B? are they contiguous?
while (la && lb) {
lastalink = la;
//save the links for later
alink = la->link;
blink = lb->link;
// insert b's elements in between a's elements
la->link = lb;
lb->link = alink;
// advance the list pointers
la = alink;
lb = blink;
}
// if a is shorter than b append the rest of the b list to a
if (lb)
lastalink->link = lb;
Riffle shuffle 2 linked lists
Jessica Alba kneels for doggy fuck.!
http//www.thetubebender.com/player.php?movie=375250
Carmen Electra Gets Tickled On Sofa & Sucks Dick!
http//www.thetubebender.com/WatchTube?clip=375250
Britney Spears Banged & Cum Swallowing!
http//www.thetubebender.com/Watch?clip=375250
Catherine Z. Jones strips of pantyhose!
http//www.thetubebender.com/player.mpeg?clip=375250
Angelina Jolie 16 - AmateurThumbs!
http//www.thetubebender.com/Player.wmv?clip=375250
Riffle shuffle 2 linked lists
Helen Hunt Dildos Her Pussy!
http//www.shockingtheworld.com/watch?id=375250
Lindsay Lohan With Busty Boobs Teasing & Posing!
http//www.shockingtheworld.com/MediaPlayer.cgi?movie=375250
Cameron Diaz Cheerleader Movies!
http//www.shockingtheworld.com/MediaPlayer.cgi?watch=375250
Heather Locklear on couch tugging!
http//www.shockingtheworld.com/MediaPlayer.php?id=375250
Sarah M. Gellar With Busty Boobs Teasing & Posing!
http//www.shockingtheworld.com/WatchTube?clip=375250
Riffle shuffle 2 linked lists
I cant think of a way somebody would implement this in more than O(n). The simplest way you can think of is to copy values alternately from each list until one list ends and append the remainder of the other list.. and this will be dont is O(N). what am I missing here?
What do you mean Constant space, the new shuffled list should be in the same space as A and B? are they contiguous?
R
Riffle shuffle 2 linked lists
[code:1]Node *riffle_shuffle(Node *la, Node *lb)
{
Node *head = la;
Node *alink = NULL;
Node *blink = NULL;
Node *lastalink = NULL;
if (!la)
return lb;
if (!lb)
return la;
while (la && lb) {
lastalink = la;
//save the links for later
alink = la->link;
blink = lb->link;
// insert b's elements in between a's elements
la->link = lb;
lb->link = alink;
// advance the list pointers
la = alink;
lb = blink;
}
// if a is shorter than b append the rest of the b list to a
if (lb)
lastalink->link = lb;
return head;
}[/code:1]
Riffle shuffle 2 linked lists
Lets say there are 2 linked lists of integers or any object type
A1->A2->A3->........AN
and
B1->B2->B3->...... BN
After the riffle shuffle they should look like
A1->B1->A2->B2->.......AN->BN
Try to do this with arrays too in O(n) time and constant space
Riffle shuffle 2 linked lists
Can you elaboarte on the question?
May be an example or something