Advertisement
smatskevich

Lesson21

Feb 22nd, 2024
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Node {
  5.   int Data;
  6.   Node* Left = nullptr;
  7.   Node* Right = nullptr;
  8. };
  9.  
  10. void DFS(Node* node) {
  11.   if (node == nullptr) return;
  12.   DFS(node->Left);
  13.   DFS(node->Right);
  14.   cout << node->Data << " ";
  15. }
  16.  
  17. int main() {
  18.   Node* root = new Node;
  19.   // (*root).Data = 10;
  20.   root->Data = 10;
  21.   root->Left = new Node;
  22.   root->Left->Data = 7;
  23.   DFS(root);
  24.  
  25.   delete root->Left;
  26.   delete root;
  27.  
  28.   return 0;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement