fork(2) download
  1.  
  2. #include <set>
  3. #include <deque>
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. template < typename T >
  8. class Tree {
  9.  
  10. struct compare {
  11. bool operator()(const Tree * t1,
  12. const Tree * t2) const {
  13. return t1-> GetContent() < t2-> GetContent();
  14. }
  15. };
  16.  
  17. typedef typename std::multiset < Tree * , typename Tree::compare > NodeSet;
  18.  
  19. private:
  20. NodeSet children;
  21. T content;
  22.  
  23. public:
  24.  
  25. Tree& AppendNode(const T& node) {
  26. Tree *t = new Tree(node);
  27. AttachTree(t);
  28. return *t;
  29. }
  30. void Clear() {
  31. typename NodeSet::iterator it = children.begin();
  32. while (children.end() != it) {
  33. children.erase( *it);
  34. delete *it;
  35. it++;
  36. }
  37.  
  38. }
  39. const T& GetContent() const {
  40. return content;
  41. }
  42. Tree(const T& root) {
  43. content = root;
  44. }
  45. void AttachTree(Tree* t) {
  46. children.insert(t);
  47. }
  48. void Visit(std::deque <T>& exp) const {
  49. exp.push_back(content);
  50. typename NodeSet::iterator it = children.begin();
  51. while (it != children.end()) {
  52. (*it) -> Visit(exp);
  53. it++;
  54. }
  55. }
  56. Tree() {}
  57. Tree(Tree & c) {
  58. c.DeepCopyTo(this);
  59. }
  60. T & operator = (const Tree & b) {
  61. b.DeepCopyTo(this);
  62. }
  63. ~Tree() {
  64. Clear();
  65. }
  66. void DeepCopyTo(Tree* dest) const {
  67. dest->content = content;
  68. typename NodeSet::iterator it = children.begin();
  69. while (it != children.end()) {
  70. Tree* t = new Tree();
  71. (*it)->DeepCopyTo(t);
  72. dest->AttachTree(t);
  73. it++;
  74. }
  75. }
  76.  
  77. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty