Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int tamano_pila=5;
  5.  
  6. class pila{
  7.  
  8. private:
  9. int cima;
  10. int arreglo_pila[tamano_pila];
  11. public:
  12. pila(){
  13. cima=-1;
  14. for (int i=0;i<tamano_pila;i++)
  15. arreglo_pila[i] = NULL;
  16. }
  17. bool empty(){
  18. if (cima==-1)
  19. return true;
  20. else
  21. return false;
  22. }
  23.  
  24. int size(){
  25.  
  26. return cima;
  27. }
  28.  
  29. int top(){
  30. if (cima>-1)
  31. return arreglo_pila[cima];
  32. }
  33. void erase(){
  34. if (cima>-1)
  35. cima=cima-1;
  36. }
  37. void insert(int elemento){
  38.  
  39. arreglo_pila[cima+1]=elemento;
  40. cima=cima+1;
  41. }
  42.  
  43. void imprimir(){
  44.  
  45. cout<<endl;
  46. cout<<"Elementos de la pila"<<endl;
  47. cout<<"--------------------"<<endl;
  48. cout<<endl;
  49. for (int i=0; i<=cima; i++)
  50.  
  51. cout<<"Elemento["<<i+1<<"]:"<<arreglo_pila[i]<<endl;
  52. }
  53. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement