{
ComplexNode* p=head;
cout<<" printListNext: "<<endl;
while(p!=NULL)
{
cout<<p->m_nValue<<" ";
p=p->m_pNext;
}
cout<<endl;
}
void printListSibling(ComplexNode* head)
{
ComplexNode* p=head;
cout<<" printListSibling: "<<endl;
while(p!=NULL)
{
cout<<p->m_nValue<<" ";
p=p->m_pSibling;
}
cout<<endl;
}
ComplexNode* copyNext(ComplexNode* head)
{
ComplexNode* p=head,*q,*cp,*cq;
while(p!=NULL)
{
q=p->m_pNext;
cp = new ComplexNode;
cp->m_nValue=p->m_nValue;
cp->m_pSibling=NULL;
p->m_pNext=cp;
cp->m_pNext=q;
p=q;
}
return head;
}
ComplexNode* copySibling(ComplexNode* head)// for all the copy element are closely near to the last element
{
ComplexNode* p=head,*q,*cp,*cq;
while(p!=NULL)
{
if (p->m_pNext&&p->m_pSibling)
{
p->m_pNext->m_pSibling=p->m_pSibling->m_pNext;
}
p=p->m_pNext->m_pNext;
}
return head;
}
void divideList(ComplexNode* head,ComplexNode* &head1,ComplexNode* &head2)
{
ComplexNode*p=head,*q;//,*pt,*qt;
if (head)
{
head1=head;
head2=head->m_pNext;
}
else
return ;
p=head1;q=head2;
while(p->m_pNext&&q->m_pNext)
{
p->m_pNext=q->m_pNext;
p=p->m_pNext;
q->m_pNext=p->m_pNext;
q=q->m_pNext;
}
p->m_pNext=NULL;
q->m_pNext=NULL;
return;
}
int _tmain(int argc, _TCHAR* argv[])
{
ComplexNode* head,*head1,*head2;
head = constructList();
head = constructListSibling(head);
printListNext(head);
printListSibling(head);
//cout<<"after copy next"<<endl;
//head = copyNext(head);
//head = copySibling(head);
//printListNext(head);
//printListSibling(head);
divideList(head,head1,head2);
cout<<"head1 is"<<endl;
printListNext(head1);
printListSibling(head1);
cout<<"head2 is"<<endl;
printListNext(head2);
printListSibling(head2);
system("pause");
return 0;
}