gpt4 book ai didi

c - 将指针分配给链表: does not contain data

转载 作者:行者123 更新时间:2023-11-30 15:11:51 24 4
gpt4 key购买 nike

所以我有一个方法来尝试查看哪个链接列表更大。如果我找到比我想要的更大的指针,那么当我在链表上进行算术时,我会从较大的值中减去较小的值,无论它是链表 A 还是链表 B。我'不过我们遇到了一些问题。首先,当我查看新分配的指针中是否有数据时,我收到一条错误消息“'->'的类型参数无效(具有'结构节点')”这是我的代码,任何帮助将不胜感激!

void subtraction(struct node** headOne, struct node** currOne, struct node** tailOne, struct node** headTwo, struct node** currTwo, struct node** tailTwo, struct node** headThree, struct node** tailThree, int lengthOne, int lengthTwo){
int numberOne, numberTwo, diff;
struct node* longest;
struct node* shortest;
printf("tailOne data = %d\n",(*tailOne)->data);
printf("tailTwo data = %d\n",(*tailTwo)->data);
if(lengthTwo > lengthOne){
longest = *currTwo;
shortest = *currOne;
}
else if (lengthOne > lengthTwo){
longest = *currOne;
shortest = *currTwo;
}
else{
if(((*tailOne)->data) > ((*tailTwo)->data)){
longest = *currOne;
shortest = *currTwo;
}
else{
longest = *currTwo;
shortest = *currOne;
}
}
while(longest){
printf("longest = %d",(*longest)->data);
}

}

int main(){
//initials
int i, number, lengthOne, lengthTwo;
char ch = 1;
//node pointers
struct node* headOne = NULL;
struct node* currOne = NULL;
struct node* tailOne = NULL;
struct node* headTwo = NULL;
struct node* currTwo = NULL;
struct node* tailTwo = NULL;
struct node* headThree = NULL;
struct node* currThree = NULL;
//create linked list
lengthOne = createLL(&headOne,&currOne, &tailOne, ch, number);
lengthTwo = createLL(&headTwo,&currTwo, &tailTwo, ch, number);
scanf("%c",&ch);
if (ch == '+'){
addition(&headOne, &currOne, &headTwo, &currTwo, &headThree, &currThree, lengthOne, lengthTwo);
}
else if(ch == '-'){
subtraction(&headOne, &currOne, &tailOne, &headTwo, &currTwo, &tailTwo, &currThree, &headThree, lengthOne, lengthTwo);
}

最佳答案

应该是longest->data(*longest).data ,不是(*longest)->data .

关于c - 将指针分配给链表: does not contain data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35388322/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com