Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct s_node {
- int value;
- struct s_node *right;
- struct s_node *left;
- } Node;
- Node* recurse(Node* root) {
- if (!root)
- return 0;
- if (root->left) {
- Node* left = recurse(root->left);
- while (left->right)
- left = left->right;
- left->right = root;
- root->left = left;
- }
- if (root->right) {
- Node* right = recurse(root->right);
- while (right->left)
- right = right->left;
- right->left = root;
- root->right = right;
- }
- return root;
- }
- Node* convert_bst(Node* bst) {
- if (!bst)
- return 0;
- recurse(bst);
- Node* left = bst;
- Node* right = bst;
- while (left->left)
- left = left->left;
- while (right->right)
- right = right->right;
- left->left = right;
- right->right = left;
- return left;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement