private static void PrintStack(StackLinkedList <int> lstStackLinkedList) { foreach (int item in lstStackLinkedList) { Console.WriteLine(item); } }
static void Main(string[] args) { //Generic Type : You can use other data types like string, double. StackLinkedList <int> lstStackLinkedList = new StackLinkedList <int>(); Console.WriteLine("Pushing item onto the Stack:"); lstStackLinkedList.Push(5); lstStackLinkedList.Push(10); lstStackLinkedList.Push(15); lstStackLinkedList.Push(20); lstStackLinkedList.Push(25); PrintStack(lstStackLinkedList); Console.WriteLine("Popping item from the Stack:"); lstStackLinkedList.Pop(); PrintStack(lstStackLinkedList); Console.WriteLine("Peeking item from the stack:"); lstStackLinkedList.Peek(); PrintStack(lstStackLinkedList); Console.WriteLine("stack contains 50 or not:"); Console.WriteLine(lstStackLinkedList.Contains(50)); Console.ReadKey(); }