(代码已写出,运行时出现了问题,求解?)已知一个不带头节点的单链表list,设计一个算法,使得链表中数据域值最大的结点被删除。

67行一下就打印不出来了不知道为什么?
源代码:

#include"stdio.h"
#include"malloc.h"
typedef struct Node
{
    int data;
    struct Node* next;
}Node;
Node* create(Node* L, int n)
{
    int x, i;
    Node* h = NULL, * s = NULL;
    h = (Node*)malloc(sizeof(Node));
    L = h;
    printf("请输入第1个数据:");
    scanf_s("%d", &x);
    h->data = x;
    for (i = 2; i <= n; i++)
    {
        printf("请输入第%d个数据:",i);
        scanf_s("%d", &x);
        s = (Node*)malloc(sizeof(Node));
        s->data = x;
        h->next = s;
        h = s;
    }
    h = NULL;
    return L;
}
void display(Node* L)
{
    Node* h;
    h = L;
    while (h)
    {
        printf("%d    ", h->data);
        h = h->next;
    }
    printf("\n");
}
Node* dele(Node* L)
{
    Node* h, * s;
    int x,i,j;
     h = L;
    while (h != NULL)
    {
        if ((h->data) > (h->next->data))x = h->data;
        h = h->next;
    }
    for (i = 1, h = L; h->data == x; i++)
        h = h->next;
    for (j = 0, h = L; h->next != NULL && j < i - 1; j++)
        h = h->next;
    s = h->next;
    h->next=h->next->next;
    free(s);
    return L;
}
void main()
{
    Node* List = NULL;
    int num;
    printf("请输入数据的个数:");
    scanf_s("%d", &num);
    List = create(List, num);
    printf("原数据:");
    display(List); printf("删除最大值后:");
    /*List=dele(List);
    printf("删除最大值后:");
    display(List);*/
}

运行结果及报错内容

img


#include"stdio.h"
#include"malloc.h"
typedef struct Node
{
    int data;
    struct Node* next;
}Node;
Node* create(Node* L, int n)
{
    int x, i;
    Node* h, * s;
    h = (Node*)malloc(sizeof(Node));
    L = h;
    printf("请输入第1个数据:");
    scanf_s("%d", &x);
    h->data = x;
    for (i = 2; i <= n; i++)
    {
        printf("请输入第%d个数据:", i);
        scanf_s("%d", &x);
        s = (Node*)malloc(sizeof(Node));
        s->data = x;
        s->next = NULL;
        h->next = s;
        h = s;
    }
    h = NULL;
    return L;
}
void display(Node* L)
{
    Node* h;
    h = L;
    while (h!=NULL)
    {
        printf("%d    ", h->data);
        h = h->next;
    }
    printf("\n");
}
Node* dele(Node* L)
{
    Node* h, * s;
    int x, i, j;
    h = L;
    x = h->data;
    while (h != NULL&&h->next!=NULL)
    {
        if ((h->data) < (h->next->data))x = h->next->data;
        h = h->next;
    }
    //for (i = 1, h = L; h->data == x; i++)
    //    h = h->next;
    if (x==L->data)
    {
        L = L->next;
    }
    for (h = L; h->next!= NULL; h = h->next)
        if (x==h->next->data)
        {
            h->next = h->next->next;
        }
    return L;
}
void main()
{
    Node* List = (Node*)malloc(sizeof(Node));
    int num;
    printf("请输入数据的个数:");
    scanf_s("%d", &num);
    List = create(List, num);
    printf("原数据:");
    display(List); 
    List=dele(List);
    printf("删除最大值后:");
    display(List);
}