Flatten BST to sorted list
// Flatten BST to Sortlisted #include <bits/stdc++.h> using namespace std ; struct Node { int data ; struct Node * left ; struct Node * right ; Node ( int val ){ data = val ; left = NULL ; right = NULL ; } }; void fun ( Node * parent ){ Node * curr = parent ; while ( curr != NULL ) cout << curr -> data << " " , curr = curr -> right ; } void inorder ( Node * curr , Node * & prev ){ if ( ! curr ) return ; inorder ( curr -> left , prev ); prev -> left = NULL ; prev -> right = curr ; prev = curr ; inorder ( curr -> right , prev ); } Node * flatten ( Node * root ){ Node * dummy = new Node ( - 1 ); Node * prev = dummy ; inorder ( root , prev ); prev -> left = NULL ; prev -> right = NULL ; Node * ret = dummy -> right ; return ret ; } int main (){ #ifndef ONLINE_JUDGE freopen ( &q