2017-02-18 3 views
0

リンクリストを逆順で印刷しようとしました。私はノード - >次の印刷しようとしたときにあなたが見るように、エラーが発生しリンクリストを再帰で印刷しようとしていますが、機能しません。

#include <stdio.h> 
#include <stdlib.h> 

typedef struct list{ 
int value; 
struct list* next; 
}list_s; 

static int g_size=sizeof(list_s); 

void printRe(list_s *node){ 
    if(node=NULL) 
     return; 
    printRe(node->next); // this is where error happens 
    printf("%d",node->value); 
} 

int main() 
{ 
    list_s* head; 
    head=(list_s*)malloc(g_size); 
    int n; 
    scanf("%d",&n); 
    int i=0; 
    int x; 
    scanf("%d",&x); 
    head->value=x; 
    head->next=NULL; 
    list_s* current; 
    current=head; 
    for(i;i<n-1;++i){ 
     current->next=(list_s*)malloc(g_size); 
     current=current->next; 
     scanf("%d",&x); 
     current->value=x; 
     current->next=NULL; 
    }; 
    printRe(head); 
    return 0; 
} 


これはコードです。なぜエラーが発生しましたか?関数を間違ってリストに渡しましたか?

ありがとうございました!

+5

if-testの 'node == NULL'は' node == NULL'にする必要があります。 – WhozCraig

+3

'gcc -Wall'が叫ぶ'警告:真理値として使用される代入の周りに括弧を付ける[-Wparentheses] if(node = NULL) ' –

答えて

1

(ノードが== NULL)場合、条件printReで()関数は

のようにする必要がある場合の代わりに、(ノード= NULL)の場合

私はそれはあなたを助けることを願っています。 ありがとう

関連する問題