Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* inicio de main.cpp */
- #include <iostream>
- #include "stack.h"
- /*
- void push(elemento); // agregar
- elemento pop(); // extraer
- bool empty(); // vacio?
- */
- using namespace std;
- int main() {
- std::cout << "Pilas!\n";
- int tmp;
- Stack<int> pila_de_enteros;
- if (pila_de_enteros.empty())
- {
- cout << "esta vacia 1" << endl;
- }
- pila_de_enteros.push(4);
- pila_de_enteros.push(50);
- pila_de_enteros.push(16);
- pila_de_enteros.push(10);
- if (pila_de_enteros.empty())
- {
- cout << "esta vacia 2" << endl;
- }
- while (!pila_de_enteros.empty())
- {
- tmp = pila_de_enteros.pop();
- cout << tmp << endl;
- }
- if (pila_de_enteros.empty())
- {
- cout << "esta vacia 3" << endl;
- }
- /* EJERCICIOS
- 1.- haga una pila de nombres de personas (string), muestre que funcione
- 2.- dada una pila de enteros, elimine los elementos con valor impar
- */
- }
- /* fin de main.cpp */
- /* inicio de stack.h */
- #ifndef STACK_H
- #define STACK_H
- template<class T>
- class Stack
- {
- public:
- Stack(){top=-1;}
- //virtual ~Stack();
- void push(T e) { top++; V[top]=e; }
- T pop() {T e; e=V[top];top--;return e; }
- bool empty() {return (top == -1); }
- protected:
- private:
- int top;
- T V[100];
- };
- #endif // STACK_H
- /* fin de stack.h */
- /* inicio de stack.cpp */
- #include "stack.h"
- /* fin de stack.cpp */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement