将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。
示例:
输入:1->3->5, 2->4->6
输出:1->2->3->4->5->6
#include <stdio.h>
#include <string.h>
#include <assert.h>
typedef struct Node
{
int data;//数据域,用来存放数据域;
struct Node* pNext;//定义一个结构体指针,指向下一次个与当前节点数据类型相同的节点
}NODE, * PNODE,**PPNODE;
//NODE等价于 struct Node; PNODE等价于struct Node *; 此处用大写是为了与变量区分,可以让人容易变出是个数据类型
/*创建一个新节点*/
PNODE Buynewnode(int x)
{
PNODE node = (PNODE)malloc(sizeof(NODE));
assert(node);/*防止申请空间失败*/
node->data = x;
node->pNext = NULL;
return node;
}
/*尾插*/
void ListPushback(PPNODE head ,int x)
{
if (*head == NULL) /*如果插入时是一个空链表*/
{
*head