Skip to content

Commit 8bbd6c5

Browse files
committed
Fix postorder traversal
1 parent 57890c2 commit 8bbd6c5

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/cjlib.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,10 @@ const char *cjlib_json_object_stringtify(const cjlib_json_object *restrict src)
701701
struct cjlib_queue object_data_q;
702702
cjlib_queue_init(&object_data_q);
703703

704-
if (-1 == cjlib_dict_postorder(&object_data_q, src)) return NULL;
704+
if (-1 == cjlib_dict_postorder(&object_data_q, (cjlib_json_object *) src)) return NULL;
705+
706+
// TODO - implement the algorithm.
705707

706-
(void) src;
707708
return NULL;
708709
}
709710

src/cjlib_dictionary.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,22 @@ int cjlib_dict_postorder(struct cjlib_queue *restrict dst, const struct avl_bs_t
107107

108108
do {
109109
if (NULL != root) {
110-
if (-1 == cjlib_queue_enqeue((void *) root->avl_data, sizeof(struct cjlib_json_data), &post_order_data_q)) return -1;
110+
if (-1 == cjlib_queue_enqeue((void *) root, sizeof(struct cjlib_json_data), &post_order_data_q)) return -1;
111111
}
112112

113113
if (NULL != root && NULL != root->avl_left) {
114-
if (-1 == cjlib_queue_enqeue((void *) root, sizeof(struct avl_bs_tree_node), &post_order_node_q)) return -1;
114+
if (-1 == cjlib_queue_enqeue((void *) &root, sizeof(struct avl_bs_tree_node *), &post_order_node_q)) return -1;
115115
}
116116

117117
if (NULL != root->avl_right) {
118-
if (-1 == cjlib_queue_enqeue((void *) root->avl_right, sizeof(struct avl_bs_tree_node *), &post_order_node_q)) return -1;
118+
if (-1 == cjlib_queue_enqeue((void *) &root->avl_right, sizeof(struct avl_bs_tree_node *), &post_order_node_q)) return -1;
119119
}
120120

121121
if (NULL != root->avl_left) {
122122
root = src->avl_left;
123123
} else {
124-
cjlib_queue_deqeue(root, sizeof(struct avl_bs_tree_node *), &post_order_node_q);
124+
cjlib_queue_deqeue(&root, sizeof(struct avl_bs_tree_node *), &post_order_node_q);
125+
break;
125126
}
126127
} while(!cjlib_queue_is_empty(&post_order_node_q));
127128

tests/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int main(void)
8585

8686
// (void) printf("%s\n", dst.c_value.c_str);
8787

88-
//cjlib_json_stringtify(&json_file);
88+
cjlib_json_stringtify(&json_file);
8989

9090
// // Close the json file.
9191
cjlib_json_close(&json_file);

0 commit comments

Comments
 (0)