Facebook
From Big Lemur, 6 Years ago, written in C++.
This paste is a reply to Untitled from Scorching Finch - view diff
Embed
Download Paste or View Raw
Hits: 392
  1. #include <memory>
  2. #include "stdafx.h"
  3.  
  4. template<class T>struct Node;
  5.  
  6. template<class T>
  7. struct Node {
  8.         T key;
  9.         std::shared_ptr<Node> left;
  10.         std::shared_ptr<Node> right;
  11.         Node(T);
  12. };
  13.  
  14. template<class T>
  15. Node<T>::Node(T item){
  16.         key = item;
  17.         left = nullptr;
  18.         right = nullptr;
  19. }
  20.  
  21. template<class T>
  22. struct BST {
  23.        
  24.         std::shared_ptr<Node<T>>root;
  25.         BST();
  26.        
  27.         bool insert(T x); //tutaj wrzucam jakiegoś przykładowo int'a
  28.                         //i teraz nie wiem czy to nie powinno być bool insert(Node<T>) żeby się zgadzało z zadaniem
  29.                         // i wówczas moim T będzi Node<T>
  30.         bool find(T x);
  31.         bool erase(T x);
  32.         Node<T>& min(void);
  33.         Node<T>& max(void); //tutaj zwracam referencje na Node<T>
  34. };
  35.