Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections;
- using System.Linq;
- using System.Text;
- namespace Generic_Stack_Implementation
- {
- class Mystack<T> : IEnumerable
- {
- T[] list = null;
- int top;
- public void push(T element)
- {
- top++;
- list[top] = element;
- }
- public Mystack(int size)
- {
- list = new T[size];
- int top = -1;
- }
- public T pop()
- {
- return (list[top--]);
- }
- public IEnumerator GetEnumerator()
- {
- return list.GetEnumerator();
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Mystack<int> mys = new Mystack<int>(5);
- mys.push(200);
- mys.push(300);
- mys.push(500);
- Console.WriteLine(mys.pop()); //pop 500
- Console.WriteLine(mys.pop());//pop 300
- IEnumerator ie = mys.GetEnumerator();
- while (ie.MoveNext())
- {
- Console.WriteLine(ie.Current);
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment