// return true or false - exist element value in stack. public bool Exist(ElementType value) { if (head == null) { return(false); } ListElement temp = head; for (temp = head; temp.Next() != null && temp.Value() != value; temp = temp.Next()) { ; } return(temp.Value() == value); }
//return position element with vale value. public Position PositionElement(ElementType value) { ListElement temp = head; int i = 0; for (temp = head; temp != null && temp.Value() != value; temp = temp.Next(), i++) { ; } if (temp.Value() == value) { return(i); } return(-1); }
/// <summary> /// Print stack. /// </summary> public void Print() { if (head == null) { Console.WriteLine("Stack is empty"); return; } ListElement pos = head; for (pos = head; pos.Next() != null; pos = pos.Next()) { Console.Write("{0} -> ", pos.Value()); } Console.Write("{0}", pos.Value()); Console.WriteLine(); }
// print stack. public void Print() { Console.WriteLine(); if (head == null) { Console.WriteLine("List is Empty"); return; } ListElement temp = head; for (temp = head; temp.Next() != null; temp = temp.Next()) { Console.Write("{0}, ", temp.Value()); } Console.WriteLine("{0}", temp.Value()); }