// LinkList.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
using namespace std;
typedef struct _node
{
int val;
struct _node* next;
}Node;
Node* MergeTwo(Node* h1,Node* h2)
{
Node *h,*a,*b;
h=new Node();
Node* pre=h;
a=h1;
b=h2;
while(a&&b)
{
if(a->val>b->val)
{
h->next=a;
h=h->next;
a=a->next;
}
else
{
h->next=b;
h=h->next;
b=b->next;
}
}
if(!a)
h->next=b;
if(!b)
h->next=a;
return pre->next;
}
int _tmain(int argc, _TCHAR* argv[])
{
int m=4;
Node* head=(Node*)malloc(sizeof(Node));
head->val=0;
head->next=NULL;
for(int i=1;i<=4;i++)
{
Node* n=(Node*)malloc(sizeof(Node));
n->val=i;
n->next=head;
head=n;
}
Node* head2=new Node();
head2->val=10;
head2->next=NULL;
Node* p2=head2;
for(int i=9;i>4;i--)
{
Node* n=(Node*)malloc(sizeof(Node));
n->val=i;
n->next=NULL;
p2->next=n;
p2=p2->next;
}
Node *tmp=MergeTwo(head,head2);
while(tmp)
{
cout<<tmp->val<<" ";
tmp=tmp->next;
}
cin.get();
return 0;
}