Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何在链表中插入数字数组?_C_Linked List_Doubly Linked List - Fatal编程技术网

C 如何在链表中插入数字数组?

C 如何在链表中插入数字数组?,c,linked-list,doubly-linked-list,C,Linked List,Doubly Linked List,我有一个任务,要做一个程序,得到14个分数,然后把它们放到一个双链表中,这样我就可以对数据进行排序,但我注意到,从本质上讲,你不能在链表中插入数字数组 int scores[15] 进入一个链接列表 #include<stdio.h> #include<stdlib.h> #include<malloc.h> #include<string.h> #include<windows.h> #include<conio.h>

我有一个任务,要做一个程序,得到14个分数,然后把它们放到一个双链表中,这样我就可以对数据进行排序,但我注意到,从本质上讲,你不能在链表中插入数字数组

int scores[15]
进入一个链接列表

#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
#include<windows.h>
#include<conio.h>

struct mhs{

    char name[30];
    int scores[15];
    int finalScore;

    struct mhs *next, *prev;

};

void data(struct mhs **head, struct mhs **node, struct mhs **tail){

    char nama[30];
    int scores[15];
    int finalScore;
    int i, sum = 0;

    system("cls");
    printf("Name: ");
    scanf("[^\n]", name);
    fflush(stdin);
    for(i = 0; i < 14 ; i++){
        printf("Score %d: ", i+1);
        scanf("%d", &scores[i]);
    }
    for(i = 13; i > 3; i--){
        sum = sum + scores[i];
    }
    printf("Final Score: %d\n", sum / 10);
    system("pause");
    (*node) = (struct mhs*) malloc(sizeof(struct mhs));
    strcpy((*node)->nama, nama);
    (*node)->scores= scores;                      //here's where I insert the scores
    (*node)->finalScore= finalScore;

    if(*head == NULL){
        *head = *node;
        *tail = *node;
    } else {
        (*tail)->next = *node;
        (*node)->prev = *tail;
        *tail = *node;
    }

}
#包括
#包括
#包括
#包括
#包括
#包括
结构mhs{
字符名[30];
智力分数[15];
国际金融中心;
结构mhs*下一个,*上一个;
};
无效数据(结构mhs**头部、结构mhs**节点、结构mhs**尾部){
char nama[30];
智力分数[15];
国际金融中心;
int i,和=0;
系统(“cls”);
printf(“名称:”);
scanf(“[^\n]”,名称);
fflush(stdin);
对于(i=0;i<14;i++){
printf(“分数%d:,i+1”);
scanf(“%d”和分数[i]);
}
对于(i=13;i>3;i--){
总和=总和+分数[i];
}
printf(“最终分数:%d\n”,总和/10);
系统(“暂停”);
(*节点)=(结构mhs*)malloc(sizeof(结构mhs));
strcpy((*节点)->nama,nama);
(*node)->scores=scores;//这里是我插入分数的地方
(*节点)->finalScore=finalScore;
如果(*head==NULL){
*头部=*节点;
*tail=*节点;
}否则{
(*tail)->next=*节点;
(*节点)->prev=*tail;
*tail=*节点;
}
}
void data是int main()中的一个函数,这就是结构使用指针的原因。 有谁能告诉我如何将数字数组添加到链表中吗?

tldr;
            tldr;
            Did you said to insert each array of elements in to a single node of linked list.
            Then you need to assign base address of array to the node of the linked list to create linked list with each node containing array elements.

            It would be like -
        node 1 - array1 elements like [1,2,3,4]
        node 2 - array2 elements like [6,4,2,4]
        ...

            If you just want to convert linked list by using array elements. Then just iterate over it.
            Like

for(int i = 0;i<array_size;i++)
p->next = a[i];
p->next = NULL
您说过要将每个元素数组插入到链表的单个节点吗。 然后,您需要将数组的基址分配给链表的节点,以创建每个节点都包含数组元素的链表。 就像- 节点1-数组1元素,如[1,2,3,4] 节点2-数组2元素,如[6,4,2,4] ... 如果只想使用数组元素转换链表。然后迭代它。 喜欢 对于(inti=0;inxt=a[i]; p->next=NULL
此函数声明无效数据(struct mhs**head,struct mhs**node,struct mhs**curr,struct mhs**tail)没有意义。例如,函数中未使用参数struct mhs**curr。
scores
是一个
int
变量,但可以像数组
scores[i]一样使用它
@vladfrommosco很抱歉,是的,函数中没有使用**curr,我正要使用**curr打印data@Ackdari很抱歉,我的代码缺少一些内容,我试图声明整数分数[15]您知道如何在链表中插入一个数字吗?您知道如何迭代数组吗?