Copy alink list:Vinisha Ma'am
2 posters
Page 1 of 1
Copy alink list:Vinisha Ma'am
U have a link list,
it has one conventional next pointer
and it has another random pinter where it can point anywhere in the list
Copy this list??
it has one conventional next pointer
and it has another random pinter where it can point anywhere in the list
Copy this list??
Last edited by ballu on Mon Feb 02, 2009 1:58 am; edited 1 time in total
ballu- Posts : 58
Join date : 2009-02-01
Re: Copy alink list:Vinisha Ma'am
suppose we have A the link list given
and A' the new link list we will make.
struct node
{
int a;
strcut node *next; //the conventional pointer pointing to next node in link list
struct node *next_ransom; //this is the pointer which can point to any node in link list
i am writing sum sort of pseudo code
first for conventional linking...create a new link list the normal way(say A') which has just 1 pointer pointing to the next node in a link list
then for connecting the other pointer...say next_ransom;
void function(node *root1,node *root2) //root1 is the head of given link list and root2 is head of new link list
{
node *temp1,*temp2;
temp1=root2;temp2=root2;
while(temp1->next!=NULL) // make adjustments such that conventional pointer of given link list starts pointing to the corresponding node in the new link list
{
previous=temp1;
temp1=temp1->next;
previous->next=temp2;
temp2=temp2->next;
}
node *ptr1,*ptr2;
ptr1=root1;ptr2=root2;
while(ptr1->next!=NULL) //then use this line for connecting ransom pointer
{
ptr2->next_ransom= ptr1->next_ransom->next;
}
and A' the new link list we will make.
struct node
{
int a;
strcut node *next; //the conventional pointer pointing to next node in link list
struct node *next_ransom; //this is the pointer which can point to any node in link list
i am writing sum sort of pseudo code
first for conventional linking...create a new link list the normal way(say A') which has just 1 pointer pointing to the next node in a link list
then for connecting the other pointer...say next_ransom;
void function(node *root1,node *root2) //root1 is the head of given link list and root2 is head of new link list
{
node *temp1,*temp2;
temp1=root2;temp2=root2;
while(temp1->next!=NULL) // make adjustments such that conventional pointer of given link list starts pointing to the corresponding node in the new link list
{
previous=temp1;
temp1=temp1->next;
previous->next=temp2;
temp2=temp2->next;
}
node *ptr1,*ptr2;
ptr1=root1;ptr2=root2;
while(ptr1->next!=NULL) //then use this line for connecting ransom pointer
{
ptr2->next_ransom= ptr1->next_ransom->next;
}
tirth- Posts : 3
Join date : 2009-01-30
Re: Copy alink list:Vinisha Ma'am
http://discuss.joelonsoftware.com/default.asp?interview.11.359006.3
check it this maybe of help..although i havnt gone through it..bt its the same question i guess
check it this maybe of help..although i havnt gone through it..bt its the same question i guess
tirth- Posts : 3
Join date : 2009-01-30
Similar topics
» List vs arrays:Vinisha Ma'am
» Structure - Vinisha Ma'am
» QUEUE using STacks:Vinisha Ma'am
» Missing and Repeated :Vinisha Ma'am
» Copy On Write
» Structure - Vinisha Ma'am
» QUEUE using STacks:Vinisha Ma'am
» Missing and Repeated :Vinisha Ma'am
» Copy On Write
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|