Advertisement
fabgonber

Untitled

Nov 16th, 2020 (edited)
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. /* inicio de main.cpp */
  2. #include <iostream>
  3. #include "stack.h"
  4.  
  5. /*
  6.   void push(elemento); // agregar
  7.   elemento pop(); // extraer
  8.   bool empty(); // vacio?
  9.  
  10. */
  11.  
  12. using namespace std;
  13.  
  14. int main() {
  15.   std::cout << "Pilas!\n";
  16.  
  17.   int tmp;
  18.  
  19.   Stack<int> pila_de_enteros;
  20.  
  21.   if (pila_de_enteros.empty())
  22.   {
  23.       cout << "esta vacia 1" << endl;
  24.   }
  25.  
  26.   pila_de_enteros.push(4);
  27.   pila_de_enteros.push(50);
  28.   pila_de_enteros.push(16);
  29.   pila_de_enteros.push(10);
  30.  
  31.   if (pila_de_enteros.empty())
  32.   {
  33.       cout << "esta vacia 2" << endl;
  34.   }
  35.  
  36.   while (!pila_de_enteros.empty())
  37.   {
  38.       tmp = pila_de_enteros.pop();
  39.       cout << tmp << endl;
  40.   }
  41.  
  42.  
  43.   if (pila_de_enteros.empty())
  44.   {
  45.       cout << "esta vacia 3" << endl;
  46.   }
  47.   /* EJERCICIOS
  48.     1.- haga una pila de nombres de personas (string), muestre que funcione
  49.     2.- dada una pila de enteros, elimine los elementos con valor impar
  50.   */
  51.  
  52. }
  53. /* fin de main.cpp */
  54.  
  55. /* inicio de stack.h */
  56. #ifndef STACK_H
  57. #define STACK_H
  58. template<class T>
  59. class Stack
  60. {
  61.     public:
  62.         Stack(){top=-1;}
  63.         //virtual ~Stack();
  64.         void push(T e) { top++; V[top]=e; }
  65.         T pop() {T e; e=V[top];top--;return e; }
  66.         bool empty() {return (top == -1); }
  67.     protected:
  68.     private:
  69.         int top;
  70.         T V[100];
  71. };
  72. #endif // STACK_H
  73.  
  74. /* fin de stack.h */
  75.  
  76. /* inicio de stack.cpp */
  77. #include "stack.h"
  78.  
  79. /* fin de stack.cpp */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement