Created
July 6, 2014 10:48
-
-
Save niksteff/d64c3962b157fa94c80b to your computer and use it in GitHub Desktop.
SimpleBINTree
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace BinTree | |
{ | |
public class Node | |
{ | |
public Node left { get; set; } | |
public Node right { get; set; } | |
public string name { get; set; } | |
public int value { get; set; } | |
} | |
public class BinTree | |
{ | |
// Root node zum speichern. | |
Node root { get; set; } | |
// Konstruktor. | |
public BinTree() | |
{ | |
} | |
public void Add(Node n) | |
{ | |
if (root == null) | |
{ | |
root = n; | |
return; | |
} | |
AddItem(root, n.value); | |
} | |
public void AddItem(Node n, int data) | |
{ | |
if (n == null) | |
{ | |
n.value = data; | |
return; | |
} | |
if (data < n.value) | |
{ | |
if (n.left == null) | |
{ | |
n.left = new Node() { value = data }; | |
} | |
else | |
{ | |
AddItem(n.left, data); | |
} | |
} else if (data > n.value) | |
{ | |
if (n.right == null) | |
{ | |
n.right = new Node() { value = data }; | |
} | |
else | |
{ | |
AddItem(n.right, data); | |
} | |
} | |
} | |
public void TraverseBinTree() | |
{ | |
return; | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
BinTree bTree = new BinTree(); | |
bTree.Add(new Node() { value = 10 }); | |
bTree.Add(new Node() { value = 1 }); | |
bTree.Add(new Node() { value = 3 }); | |
bTree.Add(new Node() { value = 24 }); | |
bTree.Add(new Node() { value = 5 }); | |
bTree.Add(new Node() { value = 18 }); | |
bTree.Add(new Node() { value = 11 }); | |
bTree.Add(new Node() { value = 13 }); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment