为什么80%的码农都做不了架构师?>>>
#include
};void PostorderVisitTree(struct Node *root)
{if (root == NULL) return;PostorderVisitTree(root->left);PostorderVisitTree(root->right);printf("%d ", root->data);
}void _delBinTree(struct Node *root)
{if (root == NULL) return;_delBinTree(root->left);_delBinTree(root->right);printf("Delete Node (data = %d)!\n", root->data);delete (root);root = NULL;
}void deleteTree(struct Node **node)
{_delBinTree(*node);*node = NULL;
}int main(int argc, char** argv)
{Node *root = new Node(1);root->left = new Node(3);root->left->left = new Node(2);root->left->right = new Node(1);root->left->right->left = new Node(1);root->right = new Node(-1);root->right->left = new Node(4);root->right->left->left = new Node(1);root->right->left->right = new Node(2);root->right->right = new Node(5);root->right->right->right = new Node(2);PostorderVisitTree(root);printf("\n");deleteTree(&root);return 0;
}
输出结果:
2 1 1 3 1 2 4 2 5 -1 1
Delete Node (data = 2)!
Delete Node (data = 1)!
Delete Node (data = 1)!
Delete Node (data = 3)!
Delete Node (data = 1)!
Delete Node (data = 2)!
Delete Node (data = 4)!
Delete Node (data = 2)!
Delete Node (data = 5)!
Delete Node (data = -1)!
Delete Node (data = 1)!