smatskevich

Tree

Dec 4th, 2021
523
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. struct Node {
  4.   int Data;
  5.   Node* Left;
  6.   Node* Right;
  7. };
  8.  
  9. void DeleteTree(Node* node) {
  10.   if (node == nullptr) return;
  11.   DeleteTree(node->Left);
  12.   DeleteTree(node->Right);
  13.   delete node;
  14. }
  15.  
  16. int main() {
  17.   Node* root = new Node;
  18.   root->Data = 2;
  19.   root->Left = nullptr;
  20.   root->Right = nullptr;
  21.  
  22.   root->Right = new Node;
  23.   root->Right->Data = 5;
  24.   root->Right->Left = nullptr;
  25.   root->Right->Right = nullptr;
  26.  
  27.   DeleteTree(root);
  28.   return 0;
  29. }
  30.  
RAW Paste Data