System.util.collections.OrderedTree.Add C# (CSharp) Method

Add() public method

Add args: ByVal key As IComparable, ByVal data As Object key is object that implements IComparable interface performance tip: change to use use int type (such as the hashcode)
public Add ( IComparable key, object data ) : void
key IComparable
data object
return void
        public void Add(IComparable key, object data)
        {
            if(key == null)
                throw(new ArgumentNullException("Key is null"));

            // traverse tree - find where node belongs
            int result = 0;
            // create new node
            OrderedTreeNode node = new OrderedTreeNode();
            OrderedTreeNode temp = rbTree; // grab the rbTree node of the tree

            while(temp != sentinelNode) {
                // find Parent
                node.Parent = temp;
                result = key.CompareTo(temp.Key);
                if(result == 0)
                    throw new ArgumentException("Key duplicated");
                if(result > 0)
                    temp = temp.Right;
                else
                    temp = temp.Left;
            }

            // setup node
            node.Key = key;
            node.Data = data;
            node.Left = sentinelNode;
            node.Right = sentinelNode;

            // insert node into tree starting at parent's location
            if(node.Parent != null) {
                result = node.Key.CompareTo(node.Parent.Key);
                if(result > 0)
                    node.Parent.Right = node;
                else
                    node.Parent.Left = node;
            }
            else
                rbTree = node; // first node added

            RestoreAfterInsert(node); // restore red-black properities

            lastNodeFound = node;

            intCount = intCount + 1;
        }