Hi,
Does anyone have an idea of how to filter an inorder print traversal for a bst?
Let's say u have 2 + nodes carrying the same data, and u only wanna print one of it out.
this is my problem.
my print output seem to be like (eg) - [number is the frequency]
A 4
A 4
A 4
AA 2
AA 2
GAA 2
and i want it to be
A 4
AA 2
GAA 2
.... I thought of something like,
to skip over the node carrying the reoccuring data. But it ended up in a 'SEG FAULT', and seems crappy to me too...Code:void print_inorder(node_t *p_ptr, char *s){ node_t *x, *y; x = p_ptr->left; y = p_ptr->right; if(p_ptr!=NULL){ if(substring(s, p_ptr->start, p_ptr->end) == substring(s, x->start, x->end)) p_ptr=x; if(substring(s, p_ptr->start, p_ptr->end) == substring(s, y->start, y->end)) p_ptr=y; print_inorder(p_ptr->left,s); printf("%s %d\n", substring(s, p_ptr->start, p_ptr->end), p_ptr->freq); print_inorder(p_ptr->right,s); } }![]()



LinkBack URL
About LinkBacks




