C语言 分配指向链表的指针:不包含数据



所以我有一个方法,我试图看看哪个链表更大。如果我找到比我想设置指向它的指针更大的一个,所以当我在链表上进行算术时,我会从较大的列表中减去较小的,无论它是链表 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 = %dn",(*tailOne)->data);
    printf("tailTwo data = %dn",(*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

相关内容

  • 没有找到相关文章

最新更新