Castle.MicroKernel.SubSystems.Naming.TreeNode.AddSibling C# (CSharp) Method

AddSibling() public method

public AddSibling ( TreeNode node ) : void
node TreeNode
return void
		public void AddSibling(TreeNode node)
		{
			if (NextSibling == null)
			{
				NextSibling = node; return;
			}

			TreeNode current = NextSibling;

			while (current.NextSibling != null)
			{
				current = current.NextSibling;
			}

			current.NextSibling = node;
		}

Usage Example

Exemplo n.º 1
0
        public void Add(ComponentName name, IHandler handler)
        {
            if (root == null)
            {
                root = new TreeNode(name, handler);
                count++;
                return;
            }

            TreeNode current = root;

            while (true)
            {
                int cmp = String.Compare(current.CompName.Service, name.Service);

                if (cmp < 0)
                {
                    if (current.Left != null)
                    {
                        current = current.Left;
                    }
                    else
                    {
                        current.Left = new TreeNode(name, handler);
                        count++;
                        break;
                    }
                }
                else if (cmp > 0)
                {
                    if (current.Right != null)
                    {
                        current = current.Right;
                    }
                    else
                    {
                        current.Right = new TreeNode(name, handler);
                        count++;
                        break;
                    }
                }
                else
                {
                    current.AddSibling(new TreeNode(name, handler));
                    count++;
                    break;
                }
            }
        }