hllo sir.....ur videos are really helpful as they provide simpler and effective technique than the book and other sources.....sir pls pls give videos on linked lists ...like sorting a list,remove middle element of a list, delete first n nodes of list and append them in the last positions,union and intersection of linked lists....all ur followers will be highly obliged
This is impractical algorithm, because it would exhaust the stack for large deep trees. There are at least 2 ways to delete the whole tree without using stack or allocating extra memory.
An amazing way to delete any tree, using c++ without any traversal, the language will do the work for us. We can use destructor functionality. #include using namespace std; template class Tree { public: Tree* left; Tree* right; T value; Tree(T value): value(value){ } ~Tree(){ if(left){ delete left, coutleft = new Tree(10); root->right->right = new Tree(10); delete root; return 0; } and there you go no need any traversal at all :__.