fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. template <typename T>
  7. class GraphNode {
  8.  
  9. public:
  10. T data;
  11. vector<GraphNode*> adj;
  12.  
  13. void Print(GraphNode<T>* node) {
  14.  
  15. if(!node) {
  16. std::cout << "*";
  17. return;
  18. }
  19.  
  20. std::cout << node->data << ":";
  21.  
  22. for(typename vector<GraphNode<T>* >::iterator iter = adj.begin();
  23. iter != adj.end();
  24. iter++)
  25. {
  26. Print(iter);
  27. }
  28. }
  29. };
  30.  
  31. template <typename T>
  32. class BinaryTreeNode : public GraphNode<T> {
  33.  
  34. public:
  35. using GraphNode<T>::data;
  36. using GraphNode<T>::adj;
  37.  
  38. BinaryTreeNode<T>* lhs;
  39. BinaryTreeNode<T>* rhs;
  40.  
  41. BinaryTreeNode() {
  42. adj.push_back(NULL);
  43. adj.push_back(NULL);
  44.  
  45. lhs = NULL;
  46. rhs = NULL;
  47. }
  48.  
  49. BinaryTreeNode(T in_data) {
  50. data = in_data;
  51.  
  52. adj.push_back(NULL);
  53. adj.push_back(NULL);
  54.  
  55. lhs = NULL;
  56. rhs = NULL;
  57. }
  58.  
  59.  
  60. BinaryTreeNode& operator=(const BinaryTreeNode& other) {
  61.  
  62. // if the other item is this, then return itself
  63. if(&other != this) {
  64. data = other.data;
  65. // copy the vector
  66. lhs = other.lhs;
  67. rhs = other.rhs;
  68. }
  69. return *this;
  70. }
  71.  
  72. };
  73.  
  74. int main() {
  75. BinaryTreeNode<int> node;
  76. cout << 42;
  77. return 0;
  78. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
42