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

标签 c pointers linked-list

所以我有一个方法来尝试查看哪个链接列表更大。如果我找到比我想要的更大的指针,那么当我在链表上进行算术时,我会从较大的值中减去较小的值,无论它是链表 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/

相关文章:

c - 同时编译.pc和.c时makefile无故退出。很奇怪

c - 评估包含未初始化指针的条件 - IN,但它会崩溃吗?

android - lsetfilecon失败:传输端点上不支持该操作

string - 将 UnsafeMutablePointer 与 String 或 Character 类型一起使用时出现不一致

java - 比较 Java 中的堆栈弹出和队列出队(回文)

Java链表查找和删除方法

c - 打印抽象语法树

c++ - int64_t 指针转换为 AVX2 intrinsic _m256i

c# - 使用从 C# 到非托管驱动程序的嵌入式指针编码结构

c++ - 为什么我们在链接列表中声明指向相同结构的指针