#include <stdio.h>
#include "stdlib.h"
typedef struct node{
int data;
struct node *next;
}LNode;
LNode *InitLinkList(){
LNode *P=(LNode*)malloc(sizeof(LNode));
P->next=NULL;
return P;
}
void insertnode(int data,LNode *p){
if(p==NULL)
printf("error");
LNode *currentnode=p;
LNode *newnode=(LNode*)malloc(sizeof(LNode));
newnode->data=data;
newnode->next=NULL;
while(currentnode->next!=NULL)
currentnode=currentnode->next;
currentnode->next=newnode;
}
void headinsert(int data,LNode *p){
if(p==NULL)
printf("error");
LNode *currentnode=p;
LNode *newnode=(LNode*)malloc(sizeof(LNode));
newnode->data=data;
newnode->next=NULL;
newnode->next=currentnode->next;
currentnode->next=newnode;
}
void forsearch(LNode *p){
LNode*fors=p->next;
while(fors!=NULL){
printf("%d ",fors->data);
fors=fors->next;
}
printf("\n");
}
void deldata(int data,LNode *p){
LNode *ndoe=p->next,*p_privious = p;
while(ndoe!=NULL){
if(ndoe->data==data){
ndoe->data=NULL;
p_privious->next=ndoe->next;
ndoe=ndoe->next;}
else{
p_privious=ndoe;
ndoe=ndoe->next;
}
}
}
void LinkListReversePrint(LNode* head){
if(head == NULL){
return;
}
LinkListReversePrint(head -> next);
printf("%d",head ->data);
}
LNode *reverseLinkList(LNode *p){
LNode*newLinkList,*Link_c=p->next;
newLinkList=InitLinkList();
while(Link_c!=NULL){
headinsert(Link_c->data,newLinkList);
Link_c=Link_c->next;
}
return newLinkList;
}
LNode *LinkListmerge(LNode* p1,LNode* p2){
LNode* new_head = NULL;
LNode* new_tail = NULL;
LNode* cur1 = p1;
LNode* cur2 = p2;
while(cur1 != NULL && cur2 != NULL){
if(cur1 -> data <= cur2 -> data){
if(new_head == NULL){
new_head = new_tail = cur1;
}
else{
new_tail -> next = cur1;
new_tail = cur1;
}
cur1 = cur1 -> next;
}
else if(cur1 -> data > cur2 -> data){
if(new_head == NULL){
new_head = new_tail = cur2;
}
else{
new_tail -> next = cur2;
new_tail = cur2;
}
cur2 = cur2 -> next;
}
}
return new_head;
}
int main () {
LNode *head,*anthead,*me1,*h ;
int num1,num2;
head=InitLinkList();
me1=InitLinkList();
for(int i=2;i<11;i+=2){
insertnode(i,me1);
}
for(int i=1;i<11;i+=2){
insertnode(i,head);
}
h=LinkListmerge(head,me1);
forsearch(head);
me1=reverseLinkList(me1);
forsearch(h);
return 0;
}