岂曰无衣264 2022-06-25 10:02 采纳率: 98.8%
浏览 34
已结题

这里使用指针创造链表,输出为什么不是“1 2 3”,而是“1 10 10”?

img


这里使用指针创造链表,输出为什么不是“1 2 3”,而是“1 10 10”?

  • 写回答

1条回答 默认 最新

  • qzjhjxj 2022-06-25 13:37
    关注

    这么改下,看得更清楚点,供参考:

    #include <stdio.h>
    #include <stdlib.h>
    struct Linkedlist{
        int  value;
        struct Linkedlist* next;
    };
    int main()
    {
        int num[10] = {1,2,3,4,5,6,7,8,9,10};
    
        struct Linkedlist head0 = {num[0],NULL};  //定义第一个结点
        struct Linkedlist *temp= &head0;   //定义结构体指针temp ,指向第一个结点
    
        struct Linkedlist head1 = {num[1],NULL}; //定义第二个结点
        temp->next = &head1;
    
        temp = temp->next;
    
        struct Linkedlist head2 = {num[2],NULL};  //定义第三个结点
        temp->next = &head2;
    
        temp = temp->next;
    
        struct Linkedlist head3 = {num[3],NULL};  //定义第四个结点
        temp->next = &head3;
    
        temp = temp->next;
    
        struct Linkedlist head4 = {num[4],NULL};
        temp->next = &head4;
    
        temp = temp->next;
    
        struct Linkedlist head5 = {num[5],NULL};
        temp->next = &head5;
    
        temp = temp->next;
    
        struct Linkedlist head6 = {num[6],NULL};
        temp->next = &head6;
    
        temp = temp->next;
    
        struct Linkedlist head7 = {num[7],NULL};
        temp->next = &head7;
    
        temp = temp->next;
    
        struct Linkedlist head8 = {num[8],NULL};
        temp->next = &head8;
    
        temp = temp->next;
    
        struct Linkedlist head9 = {num[9],NULL};
        temp->next = &head9;
    
        for(temp = &head0;temp != NULL;temp = temp->next)
            printf("%d\t",temp->value);
    
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

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

悬赏问题

  • ¥50 如何在不能联网影子模式下的电脑解决usb锁
  • ¥20 服务器redhat5.8网络问题
  • ¥15 如何利用c++ MFC绘制复杂网络多层图
  • ¥20 要做柴油机燃烧室优化 需要保持压缩比不变 请问怎么用AVL fire ESE软件里面的 compensation volume 来使用补偿体积来保持压缩比不变
  • ¥15 python螺旋图像
  • ¥15 算能的sail库的运用
  • ¥15 'Content-Type': 'application/x-www-form-urlencoded' 请教 这种post请求参数,该如何填写??重点是下面那个冒号啊
  • ¥15 找代写python里的jango设计在线书店
  • ¥15 请教如何关于Msg文件解析
  • ¥200 sqlite3数据库设置用户名和密码