Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp6
- {
- class Program
- {
- class Stack
- {
- int capacity;
- int count;
- bool isAmpty;
- bool isFull;
- int[] arr;
- public int Capacity
- {
- get { return capacity; }
- }
- public int Count
- {
- get { return count; }
- }
- public bool IsAmpty
- {
- get { return isAmpty; }
- }
- public bool IsFull
- {
- get { return isFull; }
- }
- public Stack( int _capacity)
- {
- capacity = _capacity;
- arr = new int[capacity];
- isAmpty = true;
- isFull = false;
- count = 0;
- }
- public int Pop ()
- {
- int temp = arr[count-1];
- count--;
- arr[count] = 0;
- isFull = false;
- if (count<1)
- {
- isAmpty = true;
- }
- return temp;
- }
- public int Peek ()
- {
- return arr[count-1];
- }
- public void Push(int value)
- {
- try {
- arr[count] = value;
- ++count;
- isAmpty = false;
- if (count == capacity - 1)
- {
- isFull = true;
- }
- }
- }
- static void Main(string[] args)
- {
- Stack stack = new Stack(5);
- stack.Push(3);
- stack.Push(2);
- Console.WriteLine( stack.Pop());
- Console.WriteLine(stack.Count);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement