指向链接列表的指针:不包含数据

时间:2016-02-14 04:20:22

标签: c pointers linked-list

所以我有一种方法,我试图看看哪个链表更大。如果我找到比我想设置指针更大的那个,那么当我在链表上进行算术时,无论是链表A还是链表B,我都会从较大的表中减去较小的数字。虽然有一些问题。首先,当我看到我新分配的指针中是否有数据时,我得到一个错误,说“无效的类型参数' - >'(有'struct node')”这是我的代码,任何帮助都将非常感谢!

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);
}

1 个答案:

答案 0 :(得分:1)

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