私は単純な BST ADT を作成しようとしていますが、まだ C に慣れていないため、いくつかの問題があります。
コンパイルされますが、警告と「メモ」が表示されます。プログラムを実行すると、ルートノードの1つの要素のみが出力されます(すべての要素を順番に出力したい)。
すべてのコードが必要な場合は、私が必要だと思ったコード スニペットのみを提供しました。
bst.c - BST トラバーサル メソッド
41 void bst_inorder(bst b, void f(char *str)) {
42 if (b->key == NULL) {
43 return;
44 }
45 bst_inorder(b->left, f);
46 f(b->key);
47 bst_inorder(b->right, f);
48 }
TEST.c
14 bst_inorder(my_bst, printf);
bst.h
10 extern void bst_inorder(bst b, void f(char *str));
こんな感じでまとめています
gcc -O2 -W -Wall -ansi -pedantic *.c -o TEST
これらの警告が表示されます
TEST.c: In function ‘main’:
TEST.c:14:4: warning: passing argument 2 of ‘bst_inorder’ from incompatible pointer type [enabled by default]
In file included from TEST.c:3:0:
bst.h:10:13: note: expected ‘void (*)(char *)’ but argument is of type ‘int (*)(const char * __ restrict__)’