编辑代码

#include <stdio.h>
typedef struct Node
 { int data; struct Node* next;
  } Node;
  Node* createNode(int data) 
  { Node* newNode = (Node*)malloc(sizeof(Node)); 
  if (!newNode)
   { printf("Memory allocation failed\n"); 
  exit(0); } 
  newNode->data = data; 
  newNode->next = NULL; 
  return newNode; }
    Node* mergeSortedLists(Node* LA, Node* LB) 
    { Node dummy; 
    Node* tail = &dummy;
 dummy.next = NULL; 
    while (LA != NULL && LB != NULL)
     { if (LA->data <= LB->data) 
     { tail->next = LA; LA = LA->next; }
      else { tail->next = LB; LB = LB->next; 
      } 
      tail = tail->next; }
       if (LA != NULL) 
       { tail->next = LA;
        } else 
        { tail->next = LB; } 
        return dummy.next; }
        void printList(Node* head)
         { while (head != NULL) 
         { printf("%d ", head->data);
          head = head->next; } 
          printf("\n"); }
           int main() { Node* LA = createNode(1);
            LA->next = createNode(3);
             LA->next->next = createNode(5); 
             Node* LB = createNode(2);
              LB->next = createNode(4);
               LB->next->next = createNode(6);
                Node* LC = mergeSortedLists(LA, LB); 
                printList(LC); return 0; }