« 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_MIN
11#include <unordered_map>
12using namespace std;
13#include <queue>
14
15template <typename T>
16class TreeNode
17{
18public:
19 T data;
20 vector<TreeNode<T> *> children;
21
22 TreeNode(T data)
23 {
24 this->data = data;
25 }
26};
27
28
29void deleteTree(TreeNode<int> *root)
30{
31 if (root == NULL)
32 {
33 return;
34 }
35
36 for (int i = 0; i < root->children.size(); i++)
37 {
38 deleteTree(root->children[i]);
39 }
40 delete root;
41}
42
43
44// 1 3 2 3 4 2 5 6 2 7 8 0 0 0 0 1 9 0
45int main()
46{
47
48 TreeNode<int> *newRoot = takeInputLevelWise();
49 printTree(newRoot);
50 deleteTree(newRoot);
51
52 return 0;
53}