« Deleting a tree manually
1#include <iostream>2#include <iomanip>3#include <algorithm>4#include <string>5#include <cstring>6#include <vector>7#include <cmath>8#include <map>9#include <climits>10// climits for INT_MIN11#include <unordered_map>12using namespace std;13#include <queue>1415template <typename T>16class TreeNode17{18public:19 T data;20 vector<TreeNode<T> *> children;2122 TreeNode(T data)23 {24 this->data = data;25 }26};272829void deleteTree(TreeNode<int> *root)30{31 if (root == NULL)32 {33 return;34 }3536 for (int i = 0; i < root->children.size(); i++)37 {38 deleteTree(root->children[i]);39 }40 delete root;41}424344// 1 3 2 3 4 2 5 6 2 7 8 0 0 0 0 1 9 045int main()46{4748 TreeNode<int> *newRoot = takeInputLevelWise();49 printTree(newRoot);50 deleteTree(newRoot);5152 return 0;53}