Stack Concept in .Net

A collection that works on the Last In First Out (LIFO) principle,
i.e., the last item inserted is the first item removed from the collection.
Push - To add element and
Pop – To Remove element

Example

using System;
using System.Collections;

class Test
{
static void Main()
{
Stack stack = new Stack();
stack.Push(2);
stack.Push(4);
stack.Push(6);

while(stack.Count != 0)
{
Console.WriteLine(stack.Pop());
}
}
}

Output

6
4
2

1 comment:

Jed said...

A file is used to store the names of the students. If a stack concept is used to insert or remove the names from the file, show how the following names will be inserted or removed in the sequence as follows:
a)push “Rose”
b)push “Melinda”
c)pop
d)push “Jerry”
e)push “Danny”
f)pop

please send to my account Jed_XI@yahoo.com

Most Recent Post

Most Recent Ado.net FAQ

Most Recent .Net Framework FAQ

Most Recent Configuration Files FAQ

Daily Quote, Inspiration, Motivation and More

Subscribe Blog via Email

Enter your email address: