请问如何改成递增有序的单链表,然后插入一个值为x的结点后,还保持其递增特性呢?



```c
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>

struct Node
{
    int data;//数据域
    struct Node* next;//指针域
};

struct Node* createList()
{
    struct Node* headNode = (struct Node*)malloc(sizeof(struct Node));
    //headNode成为了结构体变量
    //变量使用前必须得先被初始化
    //headNode->date=1;
    headNode->next = NULL;
    return headNode;
}

//创建节点
struct Node* createNode(int data)
{
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = data;
    newNode->next = NULL;
    return newNode;
}

//打印函数
void printList(struct Node* headNode)
{
    struct Node* pMove = headNode->next;
    while (pMove)
    {
        printf("%d\t", pMove->data);
        pMove = pMove->next;
    }
    printf("\n");
}

//插入结点,参数:插入那个链表,插入结点的数据是多少
void InsertList(struct Node* headNode, int data)
{
    //1创建插入的结点
    struct Node* newNode = createNode(data);
    newNode->next = headNode->next;
    headNode->next = newNode;
 }

//删除函数
void deleteNode(struct Node* headNode, int posData)
{
    struct Node* posNode = headNode->next;
    struct Node* posNodeFront = headNode;
    if (posNode == NULL)
        printf("无法删除 链表为空");
    else
    {
        while (posNode->data != posData)
        {
            posNodeFront = posNode;
            posNode = posNodeFront->next;
            if (posNode == NULL)
            {
                printf("没有找到相关信息,无法删除\n");
                return;
            }
        }
        posNodeFront->next = posNode->next;
        free(posNode);
    }
}

int main()
{
    struct Node* list = createList();
    InsertList(list, 1);
    InsertList(list, 2);
    InsertList(list, 3);
    printList(list);
    deleteNode(list, 2);
    printList(list);
    system("pause");
    return 0;

}
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/958914779636191.PNG "#left")


```