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 firstname.lastname@example.org. 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.Pop() Method in C#
- Stack.Contains() Method in C#
- C# Stack with Examples
- C# | How to create a Stack
- C# | Create a Stack from a collection
- C# | Convert Stack to array
- C# | Copy the Stack to an Array
- C# | Check if a Stack contains an element
- C# | Remove all objects from the Stack
- Stack.Clone() Method in C#
- How to get Synchronize access to the Stack in C#
- Stack.CopyTo() Method in C#
- Stack.GetEnumerator Method in C#
- Stack.Push() Method in C#