我臻的不会 2022-03-30 21:01 采纳率: 50%
浏览 36
已结题

劳斯发的,和书上不是一个法子啊,我真的不会,它为啥老显示"next"不在这里面呐

img


搞不懂,上课也听不懂。正文描述要超过30字?我还没有超过吗?我也妹明白

  • 写回答

3条回答 默认 最新

  • 关注

    结构体怎么定义的?跟下面的一样吗?

    struct int_linkedlist_node
    {
        int element;
        struct int_linkedlist_node* next;
    };
    
    struct int_linkedlist
    {
        struct int_linkedlist_node* head;
        int count;
    };
    
    

    按照这个结构体定义,代码修改如下:

    #include <stdio.h>
    #include <stdlib.h>
    #include "int_linkedlist.h"
    
    
    
    struct int_linkedlist* int_linkedlist_init()
    {
        struct int_linkedlist* list = NULL;
        list = (struct int_linkedlist*)malloc(sizeof(struct int_linkedlist));
        list->head = (struct int_linkedlist_node*)malloc(sizeof(struct int_linkedlist_node));
        list->head->element = -1;
        list->head->next = NULL;
        list->count = 0;
        return list;
    }
    
    void int_linkedlist_free(struct int_linkedlist* list)
    {
        struct int_linkedlist_node* node,*t;
        if (list && list->head)
        {
            node = list->head;
            while (node)
            {
                t = node->next;
                free(node);
                node = t;
            }
            list->head = 0;
            free(list);
        }
    }
    
    int int_linkedlist_count(struct int_linkedlist* list)
    {
        return list->count;
    }
    
    void int_linkedlist_add(struct int_linkedlist* list, int index, int value)
    {
        int i=1;
        struct int_linkedlist_node* p = 0,*t;
    
        if (index < 1 && index > list->count + 1)
            return;
    
        if (list == 0)
            return;
    
        p = (struct int_linkedlist_node*)malloc(sizeof(struct int_linkedlist_node));
        p->element = value;
    
        t = list->head;
        while (t && i < index)
        {
            t = t->next;
            i++;
        }
        if (t)
        {
            p->next = t->next;
            t->next = p;
        }
    
    }
    
    void int_linkedlist_remove(struct int_linkedlist* list, int index)
    {
        int i = 1;
        int_linkedlist_node* p,*t;
        if (list == 0)
            return;
        if (index <1 || index > list->count)
            return;
    
        p = list->head;
        while (p && i < index)
        {
            p = p->next;
            i++;
        }
        if (p)
        {
            t = p->next;
            if (t)
            {
                p->next = t->next;
                p->next = t->next;
                free(t);
                list->count -= 1;
            }
            
        }
    
    }
    
    
    void int_linkedlist_clear(struct int_linkedlist* list)
    {
        struct int_linkedlist_node* p,*t;
        if (list == 0)
            return;
        p = list->head;
        while (p)
        {
            t = p->next;
            free(p);
            p = t;
        }
        list->head->next = 0;
        list->count = 0;
    }
    
    int int_linkedlist_get(struct int_linkedlist* list, int index)
    {
        int i = 1;
        struct int_linkedlist_node* node;
        if (list == 0 || list->head == 0) return -1; //如果index超出链表长度,或者小于1,返回-1
        node = list->head->next;
    
        while (node && i < index)
        {
            node = node->next;
            i++;
        }
        if (node)
            return node->element;
        else
            return -1;
    }
    //i从1开始
    int int_linkedlist_lookup(struct int_linkedlist* list, int value)
    {
        int i = 1;
        struct int_linkedlist_node* p;
        if (list == 0 || list->head == 0)
            return -1;
        p = list->head->next;
        while (p && p->element != value)
        {
            p = p->next;
            i++;
        }
        if (p)
            return i;
        else
            return -1;
    }
    
    int int_linkedlist_isempty(struct int_linkedlist* list)
    {
        if (list->count == 0) return 1;
        else return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 4月8日
  • 已采纳回答 3月31日
  • 创建了问题 3月30日

悬赏问题

  • ¥15 HL7 报告转Excel 、PDF 、jpg
  • ¥18 WPF HandyControl Trigger IsSelected 触发器修改 ListBox 中 DataTemplate 模板 StackPanel 背景图片(相关搜索:触发器)
  • ¥15 下载intel stratix10对应的d5005的acceleration stack for development
  • ¥15 python-escpos 输出到CUPS PDF打印机
  • ¥20 initializer element is not constant
  • ¥200 Matlab和PSpice联合仿真不成功,matlab崩溃
  • ¥15 deepin系统下挂载nas硬盘失败有知道后续命令和步骤的吗?
  • ¥15 寻找爱立信moshell 18.0 有偿
  • ¥15 找个代做火山图,富集分析和ppi的,有偿
  • ¥15 通过摄像头实现云录制功能