运用递归将两个链表进行连接
- 建立2个数据项按从大到小排列的链表,实现2个链表的合并,并输出合并后链表的数据项。
函数代码如下
#include<iostream>
using namespace std;
struct node{
int data;
node *next;
};
node *head=NULL;node *tail=NULL;node *temp;
node *createlist(int n)
{
int num;
cin>>num;
head=new node;
if(head==NULL)
{
cout<<"No memory available!";
return NULL;
}
else
{
head->data=num;
head->next=NULL;
tail=head;
}
for(int i=0;i<n-1;i++)
{
cin>>num;