Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Binary search tree - Post-order Traversal
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { // Post-order Traversal - The root node is visited last. First we traverse the left subtree, then the right subtree and finally the root node. //Your code goes here Console.WriteLine("Hello, world!"); Tree bsTree = new Tree(); bsTree.Insert(2); bsTree.Insert(4); bsTree.Insert(6); bsTree.Insert(8); bsTree.Insert(10); bsTree.Insert(12); bsTree.Insert(1); bsTree.Insert(3); bsTree.Insert(5); bsTree.Insert(7); bsTree.Insert(9); bsTree.Insert(11); Console.WriteLine("Preorder Traversal : "); bsTree.Postorder(bsTree.ReturnRoot()); Console.WriteLine(" "); Console.WriteLine(); } } class Node { public int item; public Node left; public Node right; public void display() { Console.Write(" "); Console.Write(item); Console.Write(" "); } } class Tree { public Node root; public Tree() { root = null; } public Node ReturnRoot() { return root; } public void Insert(int id) { Node newNode = new Node(); newNode.item = id; if (root == null) root = newNode; else { Node tempNode = root; while (true) { if (id < tempNode.item) { if (tempNode.left == null) { tempNode.left = newNode; return; } tempNode = tempNode.left; } else { if (tempNode.right == null) { tempNode.right = newNode; return; } tempNode = tempNode.right; } } } } public void Postorder(Node Root) { if (Root != null) { Postorder(Root.left); Postorder(Root.right); Root.display(); } } } }
run
|
edit
|
history
|
help
0
Sri 19 Sept
الحاسوب
Remove BOLD formatting from html
Konsol Üçgen Çizimi
Bitcoins expectative :'v
Interface
Sample Linq Test
Order of Ops 6.5 (added brackets)
all possible sub strings of a given string
Failing Action<Car> To Action<List<Car>>