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);
}
該功能原型是瘋了。 10個參數?這無疑是一個標誌,你將太多的東西組合成一個功能。 – xaxxon
我同意一些更好的設計,我可以縮小參數很多,但我現在更關注指針和鏈表。 – user3260745