This repository has been archived by the owner on Jan 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HashTableWithTree.cs
68 lines (57 loc) · 1.87 KB
/
HashTableWithTree.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Text;
using System.Collections;
namespace SolucionAlumno
{
class HashTableWithTree : IOrderSerchStruct<Node>
{
private Hashtable internalTable = new Hashtable();
private BinaryTree<Node> internalTree = new BinaryTree<Node>();
#region Miembros de IOrderSerchStruct<Node>
public int Size
{
get { return internalTable.Count; }
}
public void Add(Node item)
{
BinaryTreeNode<Node> node = new BinaryTreeNode<Node>(item);
internalTree.Add(node);
internalTable.Add(item.GetHashCode(), node);
}
public void Clear()
{
internalTable.Clear();
internalTree.Clear();
}
public bool Contains(Node item)
{
return internalTable.ContainsKey(item.GetHashCode());
}
public Node FindInStruct(Node item)
{
return (internalTable[item.GetHashCode()] as BinaryTreeNode<Node>).Value;
}
public bool Remove(Node item)
{
BinaryTreeNode<Node> updateNode = internalTree.Remove(internalTable[item.GetHashCode()] as BinaryTreeNode<Node>);
internalTable.Remove(item.GetHashCode());
if (updateNode != null && updateNode.Value != null)
{
internalTable.Remove(updateNode.Value.GetHashCode());
internalTable.Add(updateNode.Value.GetHashCode(), updateNode);
}
return true;
}
public Node getMinValue()
{
return internalTree.getMinValue();
}
public Node getMinimoAndRemove()
{
Node min = internalTree.getMinValue();
this.Remove(min);
return min;
}
#endregion
}
}