Advertisement
damarijsilva

Stack.cs

Sep 14th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Collections;
  6.  
  7.  
  8. namespace TP2
  9. {
  10.     public class Stack
  11.     {
  12.         private int[] datos;
  13.         private int cima;
  14.         private int j;
  15.  
  16.         public Stack(int n)
  17.         {
  18.             this.datos = new int[n];
  19.             this.cima = 0;
  20.             j = n;          
  21.         }
  22.  
  23.         public bool estaVacia()
  24.         {
  25.             return (cima <= 0);
  26.         }
  27.  
  28.         public bool estaLlena()
  29.         {
  30.             return (cima == j);
  31.         }
  32.  
  33.         public void Push(int elemento)
  34.         {
  35.             if(!this.estaLlena() == true)
  36.             {                        
  37.                 this.datos[this.cima] = elemento;
  38.                 ++this.cima;
  39.                                
  40.             }
  41.             else
  42.                 Console.WriteLine("Esta llena");
  43.         }
  44.        
  45.  
  46.         public int pop()
  47.         {            
  48.             if (!this.estaVacia())
  49.             {
  50.                 --this.cima;            
  51.                 return this.datos[this.cima];
  52.                
  53.             }
  54.             return -1;            
  55.         }
  56.  
  57.         public int consultarCima()
  58.         {
  59.             if(!this.estaVacia())
  60.             {
  61.                 return datos[cima-1];
  62.             }
  63.             return -1;
  64.         }    
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement