bsnabg
BAN USER
Comments (4)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
void inorder( *root )
{
if( root==NULL)
return;
else
{
inorder( root->leftchild)
DLL( root->data );
inorder( root->rightchild );
}
void DLL(int t )
{
node* n;
n=new node;
n->data=t;
n->next=n->prev=NULL;
if ( list==NULL )
list=n;
else
{
n->next=list;
list->prev=n;
list=n;
}
}
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
node* copy_list( node* original )
- bsnabg July 30, 2012{
node* original_h=original;
store( original_h );
vector<node*> v;
node* copy_h=new node;
node* prev;
copy_h->data=original_h->data;
copy_h->next=NULL;
copy_h->random=original_h;
v.push_back(originl_h);
node* t=copy_h;
prev=original_h;
original_h=original_h->next;
prev->next=copy_h;
while(original_h)
{
node* tmp=new node;
tmp->data=original_h->data;
tmp->next=NULL;
tmp->random=original_h;
t->next=tmp;
t=t->next;
v.push_back(original_h);
prev=original_h;
original_h=original_h->next;
prev->next=tmp;
}
t=copy_h;
while(t)
{
t->random=t->random->random->next;
t=t->next;
}
node* restore= original;
for(int i=1;i<v.size();i++)
{
restore->next=v[i];
restore=restore->next;
}
return copy_h;
}