/Binary-Search-Tree

A binary search tree (BST) is a binary tree where each node has a comparable key (and an associated value) and satisfies the restriction that the key in any node is larger than the keys in all nodes in that node's left subtree and smaller than the keys in all nodes in that node's right subtree.

Primary LanguageC++

Binary Search Tree

Author: @037

alt text

Compile

sudo g++ -std=c++11 -o BST.exe BST.cpp

Input commands

In the input, each starts with 'e', 'i', 'd', 'oin','opre', or 'opost'.

  • i(key): Insert (key) into the BST. For example, i2 implies "Insert key 2 into the BST".
  • d(key): delete (key) from the BST. For example, d2 implies "delete key 2 from the BST". Do nothing if the BST doesn't have the key.
  • opre: output all keys via preorder walk.
  • opost: output all keys via postorder walk.
  • oin: output all keys via inorder walk.
  • e: finish your program.

Example

i3
i1
i5
i7
oin
1
3
5
7
d7
oin
1
3
5
opre
3
1
5
opost
1
5
3
e