-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f6e2f2
commit 2007437
Showing
7 changed files
with
157 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
digraph Tree { | ||
5->-5 | ||
-5->2 | ||
5->10 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
### Mini Tutorial for the BST class | ||
|
||
bst<T> -- creates an avl tree. | ||
|
||
avl tree contains: | ||
- insert | ||
- remove | ||
- search | ||
- inorder | ||
- preorder | ||
- postorder | ||
- visualize | ||
|
||
### **insert**: | ||
```cpp | ||
#include <algoplus/bst> | ||
|
||
bst<int> b; | ||
b.insert(10); | ||
b.insert(5); | ||
b.insert(4); | ||
b.insert(13); | ||
//creates a tree with elements {4,5,10,13}; | ||
``` | ||
|
||
### **remove**: | ||
```cpp | ||
#include <algoplus/bst> | ||
|
||
bst<int> b; | ||
b.insert(10); | ||
b.insert(5); | ||
b.insert(4); | ||
b.insert(13); | ||
b.remove(4); | ||
//removes the element 4 from the tree. | ||
``` | ||
|
||
### **remove**: | ||
```cpp | ||
#include <algoplus/bst> | ||
|
||
bst<int> b; | ||
b.insert(10); | ||
b.insert(5); | ||
b.insert(4); | ||
b.insert(13); | ||
b.remove(4); | ||
//removes the element 4 from the tree. | ||
``` | ||
|
||
### **search**: | ||
```cpp | ||
#include <algoplus/bst> | ||
|
||
bst<int> b; | ||
b.insert(10); | ||
b.insert(5); | ||
b.insert(4); | ||
b.insert(13); | ||
b.remove(4); | ||
|
||
//returns true if an element is in the tree. | ||
if(b.search(4)){ | ||
std::cout<< "element 4 found in the tree" << '\n'; | ||
} | ||
``` | ||
|
||
### **inorder**: | ||
```cpp | ||
#include <algoplus/bst> | ||
|
||
bst<int> b; | ||
b.insert(10); | ||
b.insert(5); | ||
b.insert(4); | ||
b.insert(13); | ||
b.remove(4); | ||
|
||
//returns the elements in inorder fashion. | ||
std::vector<int> in = b.inorder(); | ||
``` | ||
|
||
### **preorder**: | ||
```cpp | ||
#include <algoplus/bst> | ||
|
||
bst<int> b; | ||
b.insert(10); | ||
b.insert(5); | ||
b.insert(4); | ||
b.insert(13); | ||
b.remove(4); | ||
|
||
//returns the elements in preorder fashion. | ||
std::vector<int> pre = b.preorder(); | ||
``` | ||
|
||
### **postorder**: | ||
```cpp | ||
#include <algoplus/bst> | ||
|
||
bst<int> b; | ||
b.insert(10); | ||
b.insert(5); | ||
b.insert(4); | ||
b.insert(13); | ||
b.remove(4); | ||
|
||
//returns the elements in postorder fashion. | ||
std::vector<int> in = a.postorder(); | ||
``` | ||
|
||
### **visualize**: | ||
```cpp | ||
#include <algoplus/bst> | ||
|
||
bst<int> b; | ||
b.insert(10); | ||
b.insert(5); | ||
b.insert(4); | ||
b.insert(13); | ||
b.remove(4); | ||
|
||
//returns a .dot file that can easily be previewed using | ||
//vscode plugin for graphviz or local command line tools. | ||
b.visualize(); | ||
``` |