2016-07-15 3 views
-1
/** 
* Return an array of arrays of size *returnSize. 
* Note: The returned array must be malloced, assume caller calls free(). 
*/ 

     struct node{ 
     char data[3]; 
     struct node* next; 
     }; 
     int** threeSum(int* nums, int numsSize, int* returnSize) { 
      int i,j,k; 
      struct node* head=NULL; 
      struct node* current=NULL; 
      struct node* temp=NULL; 
      for(i=0;i<numsSize-2;i++){ 
       for(j=i+1;j<numsSize-1;j++){ 
        for(k=j+1;k<numsSize;k++){ 
         if((nums[i]+nums[j]+nums[k])==0){ 
          **bool ans=check(&nums[i],&nums[j],&nums[k],head);** 
          if(ans==false){ 
           temp=(struct node*)malloc(sizeof(struct node)); 
           temp->data[0]=nums[i]; 
           temp->data[1]=nums[j]; 
           temp->data[2]=nums[k]; 
           temp->next=NULL; 
           if(head==NULL){ 
            head=temp; 
            current=head; 
         } 
         else{ 
          current->next=temp; 
          current=temp; 
         } 
        } 
        else if(ans==true){ 
         continue; 
        } 
       } 
      } 
     } 
    } 
    return head; 
} 

    **bool check(int a,int b,int c,struct node* head){** 
     while(head!=NULL){ 
       if(head->next[0]==a && head->next[1]==b && head->next[2]==c){ 
       return false; 
       } 
       else{ 
       return true; 
       } 
       head=head->next; 
     } 
} 

「『チェック』の相反するタイプ」を言って:)コンパイルエラー親切.... は、事前にありがとうHELP ~~~~ 私はここに参照パラメータに関する何かが足りないと思う~~~~

+1

ヘッド= head-> nextは決して呼び出されません(これはエラーではありません) –

+1

'threeSum'の実装の上に' check'の実装を移動するか、関数を適切にプロトタイプします。あなたのコンパイラが関数 'check'が' int'を返す「暗黙の宣言」について警告しなかった場合は、あなたの警告レベルをペタニックにする必要があります。 * real *宣言を 'threeSum'で利用できるようにすると、まったく異なるエラー(パラメータ型の不一致)が現れるはずですが、それは別の問題です。 – WhozCraig

答えて

1

check()の定義によると、check()へのポインタではない値を渡す必要があります。ライン

bool ans=check(&nums[i],&nums[j],&nums[k],head); 
//-------------^ 

nums[i]と他人のために&を削除します。

0

としてcheckのプロトタイプを考える:コール

bool ans=check(&nums[i],&nums[j],&nums[k],head); 

が間違っている

bool check(int a,int b,int c,struct node* head) 

。これは、(&のドロップ)する必要があります:あなたはthreeSumからそれを呼び出す前に

また
bool ans=check(nums[i], nums[j], nums[k],head); 

は、checkの宣言を提供しています。

それ以外の場合、コンパイラは入力タイプと戻り値の型についての仮定をcheckとします。

+0

まだ同じエラー:(@RSahu私は実際にurオプションを実際に試した。 –

+0

@aayushnigam、更新された答えを参照してください。 –

+0

ありがとう@RSahu .......私は宣言のチェックを欠いていた... :) –

関連する問題