SE250:lab-7:rthu009
Lab 7 rthu009
Ahhh the code didn't compile on visual studio gave me tons of errors so i used cygdrive program to compile the code and ran it and the code work fine lol........
Trying the program out for the first time
After compiling the code the program came out with the symbol ">". I have typed Help and it came up with the list of commands I can use to work the program.
*insert command : "insert str","i str" I have entered "i 4" to start with and the program displayed "4" At that point i assumed that the program selected the "4" to be the parent node and so I went on and added more elements.
Inserting 6 elements into the tree *i 4,i 6,i 2, i 01, i 5,i 2.5 [4,2,1,5,2.5,8] After inserting these elements my tree looked like this: 01 2 2.5 4 5 6 8 This proves that the tree is created properly using 4 as the main node and adding elements into its left and right branches respectively
Using left right and root commands I was able to navigate the tree branches and also able to delete a specific node my selecting it through left right commands
e.g 01 2 2.5 4 5 6 8(*) <------ Currently selected branch node
>delete will delete eight from the branch
- A bug was found on the program is that using the command clear tree will make the program to crash and also if you need to insert the element "1" to the tree it must be entered as "01" not "1" because the program assume "1" to be as "10" i think.
Rotating the nodes
The command rr or rotate right and rl or rotate left will rotate the selected node to either left or right.
e.g 01 2 2.5 4 4.5 5 6(*) <------ Currently selected node* 8
The command rotate right(rr) will rotate the tree: 01 2 2.5 4 4.5 5 6(*) <------ Currently selected node* 8