public T Pop() { if (first == null) { throw new IndexOutOfRangeException(); } var popResult = first; nodes.Remove(popResult.Value); first = first.Next; if (first != null) { first.Previous = null; } return(popResult.Value); }
public void Push(T value) { if (nodes.ContainsKey(value)) { throw new ArgumentException("Hash stack can't push equal elements!"); } if (first == null) { first = new HashStackNode <T>(value); } else { var newNode = new HashStackNode <T>(value); newNode.Next = first; first.Previous = newNode; first = newNode; } nodes[value] = first; }
public void Clear() { nodes.Clear(); first = null; }