Example #1
0
		public bool Remove(RankElement<TKey, TValue> element)
		{
			if (!_NodeDic.ContainsKey(element.Key))
			{
				return false;
			}
			var node = _NodeDic[element.Key];
			//_NodeDic.Remove(element.Key);
			var replaceNode = FindMin(node.RightSon);
			if (replaceNode == null)
			{
				replaceNode = FindMax(node.LeftSon);
			}
			if (replaceNode == null)
			{
				_Root = null;
			}
			else
			{
				var tmp = node.Element;
				node.Element = replaceNode.Element;
				replaceNode.Element = tmp;
				DeleteOneChild(replaceNode);
			}			
			return true;
		}
Example #2
0
		public bool Add(RankElement<TKey, TValue> element)
		{
			if (_NodeDic.ContainsKey(element.Key))
			{
				return false;
			}
			var node = Node.Create(element);
			node.LeftSon = _NIL;
			node.RightSon = _NIL;
			_NodeDic.Add(element.Key, node);
			
			if (_Root == null)
			{
				_Root = node;
			}
			else 
			{
				Node nextNode = _Root;
				Node curNode = null;
				do
				{
					curNode = nextNode;
					nextNode = curNode.Element.Value.CompareTo(element.Value) > 0 ? curNode.LeftSon : curNode.RightSon;
				} while (nextNode != _NIL);
				node.Parent = curNode;
				if (curNode.Element.Value.CompareTo(element.Value) > 0)
				{
					curNode.LeftSon = node;
				}
				else
				{
					curNode.RightSon = node;
				}
			}
			Insert_Case1(node);
			return true;
		}
Example #3
0
		public void CreateNode(RankElement<TKey, TValue> element)
		{
			var node = Node.Create(element);
		}
Example #4
0
		public void Regist(RankElement<TKey, TValue> element)
		{
			element.SetSign(_Sign, SignUpdate);
		}
Example #5
0
			public static Node Create(RankElement<TKey, TValue> value)
			{
				var node = new Node();
				node.Element = value;
				return node;
			}