Nikel_Chieh 2022-02-26 10:59 采纳率: 83.3%
浏览 36
已结题

关于#链表#的问题,请各位专家解答!(语言-c语言)


#include <stdio.h>
#include <stdlib.h>

typedef struct node 
{
    int date;
    struct node *next;
}Node;

int main()
{
    //creat_linklist
    Node *head = NULL, *current, *previous;
    int n;
    scanf("%d", &n);
    while (n--)
    {
        current = (Node *)malloc(sizeof(Node *));
        scanf("%d", &current->date);
        current->next = NULL;
        if (head==NULL)
            head = current;
        else
            previous->next = current;
        previous = current;
    }

    Node *temp;
    Node *read;
    temp = (Node *)malloc(sizeof(Node *));
    scanf("%d", &temp->date);  //insert_date
    read = head;
    while ((read->next->date)>=(temp->date))
        read = read->next;
    temp->next = read->next;
    read->next = temp;

    read = head;
    while (read!=NULL)
    {
        printf("%d ", read->date);
        read = read->next;
    }
}

img

插入位置为什么不对

  • 写回答

2条回答 默认 最新

      报告相同问题?

      问题事件

      • 系统已结题 3月6日
      • 已采纳回答 2月26日
      • 创建了问题 2月26日

      悬赏问题

      • ¥30 VB6.0操作 webview2内核的浏览器如何精确实现网页弹窗处置
      • ¥15 pr导出的视频打不开,提示“缺少编解码器”怎么解决
      • ¥15 html里js获取php参数值不成功,帮改代码
      • ¥20 如何控制ant design的InputNumber组件 最多输入5位小数
      • ¥15 c语言学生基本信息管理系统
      • ¥100 火车头采集器采集求解
      • ¥88 关于#运行时间 时间重叠 和非重叠#的问题,如何解决?
      • ¥15 C语言,密切接触者追踪
      • ¥20 关于计算机网络问题,请附带讲解
      • ¥30 自动识别图像目标并判断