Thursday, July 1, 2010

COLLECTIONS INTERFACE USING STACK

Represents a simple last-in-first-out (LIFO) non-generic collection of objects.

Namespace: System.Collections

First action you need to do on Stack is Push elements into it.
The Pop method on stack, and also the Peek method. When you call Pop, the elements from the top of the Stack is returned, and the element is removed from the collection.
The Pop and Peek methods both act on the top of Stack.


Example Programe

using System;
using System.Collections;
class stack
{
public static void Main(string[] args)
{
Stack s1=new Stack();
s1.Push(10);
s1.Push(20);
s1.Push(30);
s1.Push(40);

Console.WriteLine(s1.Pop());
Console.WriteLine(s1.Peek());
Console.WriteLine(s1.Pop());
}
}

No comments:

Post a Comment