/// <summary> /// Печать стека /// </summary> /// <returns>строковое представление стека</returns> public string Print() { if ((linlist != null) && (linlist.Length > 0)) { int count = this.Count; string result = ""; LinearList <T> lnold = new LinearList <T>(); for (int i = 0; linlist.Length > 0; i++) { result = result + this.Peek().ToString() + " "; lnold.AddFront(this.Pop()); } linlist = lnold; Count = count; return(result); } else { throw new InvalidOperationException("Стек пуст"); } }
/// <summary> /// Проверяет наличие элемента в стеке /// </summary> /// <param name="value">значение для поиска</param> /// <returns>true - если элемент найден. false - если элемент не найден</returns> public bool Contains(T value) { if ((linlist != null) && (linlist.Length > 0)) { int count = this.Count; bool result = false; LinearList <T> lnold = new LinearList <T>(); for (int i = 0; linlist.Length > 0; i++) { if (value.ToString() == this.Peek().ToString()) { result = true; } lnold.AddFront(this.Pop()); } linlist = lnold; Count = count; return(result); } else { throw new InvalidOperationException("Стек пуст"); } }