Problem p02283 (C++) — buggy submission, verdict: Runtime Error

#include <assert.h>
#include <climits>
#include <iostream>
#include <string>

struct TNode {
  int Value;
  TNode *Parent;
  TNode *Left;
  TNode *Right;

  TNode();
  TNode(int AValue, TNode *AParent);
};

TNode::TNode() {
  Value = INT_MAX;
  Parent = NULL;
  Left = NULL;
  Right = NULL;
}

TNode::TNode(int AValue, TNode *AParent) {
  Value = AValue;
  Parent = AParent;
  Left = NULL;
  Right = NULL;
}
void Insert(int Key, TNode *Root);
void Delete(TNode *Root) {
  if (Root == NULL)
    return;
  Delete(Root->Left);
  Delete(Root->Right);
  delete Root;
}

void AddLeft(int Key, TNode *Root) {
  assert(Root != NULL);
  if (Root->Left == NULL) {
    TNode *Left = new TNode(Key, Root);
    Root->Left = Left;
  } else {
    Insert(Key, Root->Left);
  }
}

void AddRight(int Key, TNode *Root) {
  assert(Root != NULL);
  if (Root->Right == NULL) {
    TNode *Right = new TNode(Key, Root);
    Root->Right = Right;
  } else {
    Insert(Key, Root->Right);
  }
}

void Insert(int Key, TNode *Root) {
  assert(Root != NULL);
  if (Root->Value == Key)
    return;
  if (Root->Value == INT_MAX) {
    Root->Value = Key;
    return;
  }
  if (Root->Value > Key) {
    AddLeft(Key, Root);
  } else {
    AddRight(Key, Root);
  }
}

void OutputPreOrder(const TNode *Root) {
  if (Root == NULL)
    return;
  std::cout << " " << Root->Value;
  OutputPreOrder(Root->Left);
  OutputPreOrder(Root->Right);
}

void OutputInorder(const TNode *Root) {
  if (Root == NULL)
    return;
  OutputInorder(Root->Left);
  std::cout << " " << Root->Value;
  OutputInorder(Root->Right);
}

void Print(const TNode *Node) {
  OutputInorder(Node);
  std::cout << std::endl;
  OutputPreOrder(Node);
  std::cout << std::endl;
}

void DoOrder(const std::string &Order, TNode *Root) {
  if (Order == "insert") {
    int Key = 0;
    std::cin >> Key;
    Insert(Key, Root);
  } else if (Order == "print") {
    Print(Root);
  }
}

int main() {
  int Count = 0;
  std::cin >> Count;
  TNode *Root = new TNode();
  for (int i = 0; i < Count; ++i) {
    std::string Order;
    std::cin >> Order;
    DoOrder(Order, Root);
  }
  Delete(Root);
  return 0;
}

Error: 0

Fixed submission:

#include <climits>
#include <iostream>
#include <string>

struct TNode {
  int Value;
  TNode *Parent;
  TNode *Left;
  TNode *Right;

  TNode();
  TNode(int AValue, TNode *AParent);
};

TNode::TNode() {
  Value = INT_MAX;
  Parent = NULL;
  Left = NULL;
  Right = NULL;
}

TNode::TNode(int AValue, TNode *AParent) {
  Value = AValue;
  Parent = AParent;
}
void Insert(int Key, TNode *Root);
void Delete(TNode *Root) {
  if (Root == NULL)
    return;
  Delete(Root->Left);
  Delete(Root->Right);
  delete Root;
}

void AddLeft(int Key, TNode *Root) {
  if (Root == NULL)
    return;
  if (Root->Left == NULL) {
    TNode *Left = new TNode(Key, Root);
    Root->Left = Left;
  } else {
    Insert(Key, Root->Left);
  }
}

void AddRight(int Key, TNode *Root) {
  if (Root == NULL)
    return;
  if (Root->Right == NULL) {
    TNode *Right = new TNode(Key, Root);
    Root->Right = Right;
  } else {
    Insert(Key, Root->Right);
  }
}

void Insert(int Key, TNode *Root) {
  if (Root == NULL)
    return;
  if (Root->Value == Key)
    return;
  if (Root->Value == INT_MAX) {
    Root->Value = Key;
    return;
  }
  if (Root->Value > Key) {
    AddLeft(Key, Root);
  } else {
    AddRight(Key, Root);
  }
}

void OutputPreOrder(const TNode *Root) {
  if (Root == NULL)
    return;
  std::cout << " " << Root->Value;
  OutputPreOrder(Root->Left);
  OutputPreOrder(Root->Right);
}

void OutputInorder(const TNode *Root) {
  if (Root == NULL)
    return;
  OutputInorder(Root->Left);
  std::cout << " " << Root->Value;
  OutputInorder(Root->Right);
}

void Print(const TNode *Node) {
  OutputInorder(Node);
  std::cout << std::endl;
  OutputPreOrder(Node);
  std::cout << std::endl;
}

void DoOrder(const std::string &Order, TNode *Root) {
  if (Order == "insert") {
    int Key = 0;
    std::cin >> Key;
    Insert(Key, Root);
  } else if (Order == "print") {
    Print(Root);
  }
}

int main() {
  int Count = 0;
  std::cin >> Count;
  TNode *Root = new TNode();
  for (int i = 0; i < Count; ++i) {
    std::string Order;
    std::cin >> Order;
    DoOrder(Order, Root);
  }
  Delete(Root);
  return 0;
}