2016-02-14 50 views
0

所以我有一个方法,我试图查看哪个链表更大。如果我发现大于我想设置一个指针的指针,那么当我在链表上进行算术运算时,我将减去较大的较小值,无论它是链表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); 
} 
+0

该功能原型是疯了。 10个参数?这无疑是一个标志,你将太多的东西组合成一个功能。 – xaxxon

+0

我同意一些更好的设计,我可以缩小参数很多,但我现在更关注指针和链表。 – user3260745

回答

1

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

+0

工作!我想我只是完全被指针弄糊涂了。不过谢谢。 – user3260745