编辑代码

#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 ;
    //h=head;
    
    int num1,num2;
    head=InitLinkList();
    me1=InitLinkList();
    /*for(int i=0;i<5;i++){
        scanf("%d",&num1);
        insertnode(num1,head);
    }
    for(int i=0;i<5;i++){
        scanf("%d",&num2);
        insertnode(num2,me1);
    }*/
    for(int i=2;i<11;i+=2){
         
        insertnode(i,me1);
    }
    for(int i=1;i<11;i+=2){
         
        insertnode(i,head);
    }
     
    //insertnode(3,head);
     h=LinkListmerge(head,me1);
    //deldata(3,head);
    //LinkListReverse(h);
    forsearch(head);
     
    
    me1=reverseLinkList(me1);
    forsearch(h);
    //LinkListReverse(head);
    //LinkListReversePrint(head);
	return 0;
}