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 DemoStack1
- {
- class Stack
- {
- private int dimension;
- private char[] datos;
- private int cuenta;
- public Stack(int dimension = 10)
- {
- this.dimension = dimension;
- this.datos = new char[dimension];
- this.cuenta = 0;
- }
- public void Push(char elemento)
- {
- if (this.cuenta >= this.dimension)
- {
- throw new Exception("Error la Pila está llena ...");
- }
- this.datos[this.cuenta] = elemento;
- ++this.cuenta;
- }
- public char Pop()
- {
- if (this.isEmpty)
- {
- throw new Exception("Error la Pila está vacía ...");
- }
- --this.cuenta;
- return this.datos[this.cuenta];
- }
- public char Peek()
- {
- if (this.isEmpty)
- {
- throw new Exception("La pila está vacía ...");
- }
- return this.datos[this.cuenta - 1];
- }
- public bool isEmpty
- {
- get { return this.cuenta <= 0; }
- }
- public int Count {
- get { return this.cuenta; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement