Stack is a linear data structure. It follows LIFO(Last In First Out) pattern for Input/output. Following three basic operations are performed in the stack:
- Push: Adds an item in the stack. If the stack is full, then it is said to be a stack Overflow condition.
- Pop: Removes an item from the stack. The items are popped in the reversed order in which they are pushed. If the stack is empty, then it is said to be a stack Underflow condition.
- Peek : Return the topmost element of stack.
Given below is the C# code to implement Stack using Arrays
Items in the Stack are : 40 30 20 10 The topmost element of Stack is : 40 Item popped from Stack : 40 Items in the Stack are : 30 20 10
This article is contributed by Ankit Sharma. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Stack.Pop() Method in C#
- C# Stack with Examples
- Stack.Contains() Method in C#
- C# | How to create a Stack
- C# | Stack Class
- Stack.ToArray() Method in C#
- Stack.Synchronized() Method in C#
- Stack.Push() Method in C#
- Stack.Equals() Method in C#
- Getting an enumerator that iterates through the Stack in C#
- Removing the object from the top of the Stack in C#
- Stack.Count Property in C#
- Stack.GetEnumerator Method in C#
- Stack.CopyTo() Method in C#
- Stack.IsSynchronized Property in C#