二分木を表す C 構造体があります。
struct btree {
char *word;
int frequency;
struct btree *left;
struct btree *right;
};
渡されたバイナリツリー内btree_list(struct btree*)
のすべてのオブジェクトの配列を返す関数を作成したいと思います。btree
注文は関係ありません。
この関数がどのように機能するかの例を次に示します。
struct btree *T = populate_with_random_values();
struct btree *entries = (struct btree*) malloc(sizeof(struct btree) * btree_size(T));
entries = btree_list(T);
while (*entries != NULL) {
printf("There are %d occurences of the word %s", entries->frequency, entries->word);
entries++;
}
また、 の各要素に対してE
、entries
技術的に使用されていないため、 に設定する必要がありますE->left
。これを実装するにはどうすればよいですか?E->right
NULL