Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* INICIO DE main.cpp */
- #include <iostream>
- #include "colaint.h"
- using namespace std;
- int main() {
- cout << "Ejemplo de Colas\n";
- ColaInt la_cola;
- int temp, i;
- cout << "Agregando Datos\n";
- la_cola.agregar(4);
- la_cola.agregar(7);
- la_cola.agregar(2);
- la_cola.agregar(9);
- la_cola.agregar(3);
- la_cola.agregar(2);
- la_cola.agregar(1);
- la_cola.agregar(0);
- cout << "Extrayendo 2 datos:\n";
- temp = la_cola.extraer();
- cout << "a) " << temp << " \n";
- temp = la_cola.extraer();
- cout << "b) " << temp << " \n";
- cout << "Agregando Datos\n";
- la_cola.agregar(5);
- la_cola.agregar(6);
- cout << "Extraer hasta acabar:\n";
- while (!la_cola.vacia())
- {
- temp = la_cola.extraer();
- cout << "?) " << temp << " \n";
- }
- }
- /* FIN DE main.cpp */
- /* INICIO DE colaint.h */
- #ifndef COLAINT_H
- #define COLAINT_H
- #define MAX 1000
- class ColaInt
- {
- public:
- ColaInt();
- ~ColaInt();
- void agregar(int elemento);
- int extraer();
- bool vacia();
- bool vacio();
- protected:
- private:
- int los_datos[MAX];
- int primero, ultimo;
- };
- #endif // COLAINT_H
- /* FIN DE colaint.h */
- /* INICIO DE colaint.cpp */
- #include "colaint.h"
- ColaInt::ColaInt()
- {
- this->primero = 0;
- this->ultimo = 0;
- }
- ColaInt::~ColaInt()
- {
- //destructor
- }
- void ColaInt::agregar(int elemento)
- {
- los_datos[this->ultimo] = elemento;
- this->ultimo++;
- }
- int ColaInt::extraer()
- {
- int temp = los_datos[this->primero];
- this->primero++;
- return temp;
- }
- bool ColaInt::vacia()
- {
- if (this->primero==this->ultimo)
- {
- return true;
- }
- else
- {
- return false;
- }
- this->primero = 0;
- this->ultimo = 0;
- }
- bool ColaInt::vacio()
- {
- return this->vacia();
- }
- /* FIN DE colaint.cpp */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement