![]() ![]() Void dump_BST(const char *tag, const struct Node *node) ![]() Node->data, (void *)node, (void *)node->left, (void *)node->right) Static void dump_BST_nodes(const struct Node *node) Struct Node *next = (temp = NULL) ? NULL : temp->left Struct Node *temp = (struct Node *)malloc(sizeof(struct Node)) Struct Node *temp1 = (struct Node *)malloc(sizeof(struct Node)) ![]() Struct Node *Insert(struct Node *root, char x) Struct Node *Insert(struct Node *, char x) This code has a function dump_BST that dumps the data in the tree for debugging purposes (and an auxilliary function dump_BST_node() that implements a pre-order traversal while printing. This seems to be the correct prescription. I've not tested it, but maybe (just maybe), you need to replace temp->data = temproot->data Īnd then in deq() you should have struct Node *next = temp->left You can do this by using the left element to point to the node and the right element to point to the next item in the queue. Struct Node* temp = (struct Node*)malloc(sizeof(struct Node)) Īs noted in the comments, you need to enqueue the pointers to the nodes in the tree structures - not the data. Struct Node* temp1 = (struct Node*)malloc(sizeof(struct Node)) Struct Node* Insert(struct Node* root,char x) Struct Node* Insert(struct Node* ,char x) I expected to get all the characters (which I had input in the main function) to be printed in some order. On running the program, I get infinite 'G' as my output. Here I tried writing code for Level Order Transversal and I am not getting the required output. Right now I am implementing BST's and they seem to be pretty complicated. I started studying data structures and was okay with linked lists, stacks, and queues. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |