~ubuntu-branches/ubuntu/raring/openmcdf/raring

« back to all changes in this revision

Viewing changes to src/OLECompoundFileStorage/BinaryTree/BinaryTreeNode.cs

  • Committer: Package Import Robot
  • Author(s): Mathieu Malaterre
  • Date: 2012-05-04 10:00:39 UTC
  • Revision ID: package-import@ubuntu.com-20120504100039-6opexlhz3d4cdj3y
Tags: upstream-1.5.2
Import upstream version 1.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#region Using directives
 
2
 
 
3
using System;
 
4
using System.Collections;
 
5
using System.Collections.Generic;
 
6
using System.Text;
 
7
 
 
8
#endregion
 
9
 
 
10
namespace BinaryTrees
 
11
{
 
12
    /// <summary>
 
13
    /// The BinaryTreeNode class represents a node in a binary tree, or a binary search tree.
 
14
    /// It has precisely two neighbors, which can be accessed via the Left and Right properties.
 
15
    /// </summary>
 
16
    /// <typeparam name="T">The type of data stored in the binary tree node.</typeparam>
 
17
    public class BinaryTreeNode<T> : Node<T>
 
18
    {
 
19
        #region Constructors
 
20
        public BinaryTreeNode() : base() {}
 
21
        public BinaryTreeNode(T data) : base(data, null) {}
 
22
        public BinaryTreeNode(T data, BinaryTreeNode<T> left, BinaryTreeNode<T> right)
 
23
        {
 
24
            base.Value = data;
 
25
            NodeList<T> children = new NodeList<T>(2);
 
26
            children[0] = left;
 
27
            children[1] = right;
 
28
 
 
29
            base.Neighbors = children;
 
30
        }
 
31
        #endregion
 
32
 
 
33
        #region Public Properties
 
34
        public BinaryTreeNode<T> Left
 
35
        {
 
36
            get
 
37
            {
 
38
                if (base.Neighbors == null)
 
39
                    return null;
 
40
                else
 
41
                    return (BinaryTreeNode<T>) base.Neighbors[0];
 
42
            }
 
43
            set
 
44
            {
 
45
                if (base.Neighbors == null)
 
46
                    base.Neighbors = new NodeList<T>(2);
 
47
 
 
48
                base.Neighbors[0] = value;
 
49
            }
 
50
        }
 
51
 
 
52
        public BinaryTreeNode<T> Right
 
53
        {
 
54
            get
 
55
            {
 
56
                if (base.Neighbors == null)
 
57
                    return null;
 
58
                else
 
59
                    return (BinaryTreeNode<T>) base.Neighbors[1];
 
60
            }
 
61
            set
 
62
            {
 
63
                if (base.Neighbors == null)
 
64
                    base.Neighbors = new NodeList<T>(2);
 
65
 
 
66
                base.Neighbors[1] = value;
 
67
            }
 
68
        }
 
69
        #endregion
 
70
    }
 
71
}