got the code for BT to BST from a site.. btree* max_tree(btree *root) { if(root == NULL) return root; btree * current = root; while(current->right != NULL) { current = current->right; } return current; } btree * min_tree(btree *root) { if(root == NULL) return root; btree * current = root; while(current->left != NULL) { current = current->left; } return current; } void binarytreetobst(btree *root) { //base-case tree is empty if(root == NULL) return; else if(root->left == NULL && root->right == NULL) //base-case tree of size 1 return; else { binarytreetobst(root->left); binarytreetobst(root->right);
btree* max = max_tree(root->left); if(max && max->data > root->data) { int temp = root->data; root->data = max->data; max->data = temp; binarytreetobst(root->left); } btree* min = min_tree(root->right); if(min && min->data < root->data) { int temp = root->data; root->data = min->data; min->data = temp; binarytreetobst(root->right); } } } On Jul 18, 7:24 pm, Dumanshu <duman...@gmail.com> wrote: > 1. //BT to BST - function used is to swap values > > Node* bubbleData(Node *root) > { > if(!root) > return NULL; > if(root->right) > { > if(root->data> root->right->data) > swap(&(root->data),&(root->right->data)); > root->right = bubbleData(root->right);} > > if(root->left) > { > if(root->data < root->left->data) > swap(&(root->data),&(root->left->data)); > root->left = bubbleData(root->left);} > > return bubbleData(root); > > } > > any case missing?? > > 3. Do we have to give an algorithm for garbage collection like Mark > sweep algo or Do we have to write a code? if code, plz tell how to > write? > > On Jul 18, 4:59 pm, Balaji S <balaji.ceg...@gmail.com> wrote: > > > > > 1. Convert a binary tree to binary search tree inplace.. > > 2. Convert a DLL to a binary search tree that is balanced. > > 3. Implement a C++ garbage collector efficiently > > > -- > > With Regards, > > Balaji.S- Hide quoted text - > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.