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.
- C# | Stack Class
- Stack.Contains() Method in C#
- C# | How to create a Stack
- C# Stack with Examples
- Stack.Pop() Method in C#
- C# | Copy the Stack to an Array
- C# | Create a Stack from a collection
- C# | Check if a Stack contains an element
- C# | Convert Stack to array
- C# | Remove all objects from the Stack
- Stack.Equals() Method in C#
- Removing the object from the top of the Stack in C#
- Getting an enumerator that iterates through the Stack in C#
- Stack.CopyTo() Method in C#
- Stack.GetEnumerator Method in C#