Advertisement
fabgonber

Untitled

Oct 26th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. /* INICIO DE main.cpp */
  2. #include <iostream>
  3. #include "colaint.h"
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.   cout << "Ejemplo de Colas\n";
  9.   ColaInt la_cola;
  10.   int temp, i;
  11.  
  12.   cout << "Agregando Datos\n";
  13.   la_cola.agregar(4);
  14.   la_cola.agregar(7);
  15.   la_cola.agregar(2);
  16.   la_cola.agregar(9);
  17.   la_cola.agregar(3);
  18.   la_cola.agregar(2);
  19.   la_cola.agregar(1);
  20.   la_cola.agregar(0);
  21.  
  22.  
  23.   cout << "Extrayendo 2 datos:\n";
  24.   temp = la_cola.extraer();
  25.   cout << "a) " << temp << " \n";
  26.   temp = la_cola.extraer();
  27.   cout << "b) " << temp << " \n";
  28.  
  29.   cout << "Agregando Datos\n";
  30.   la_cola.agregar(5);
  31.   la_cola.agregar(6);
  32.  
  33.   cout << "Extraer hasta acabar:\n";
  34.   while (!la_cola.vacia())
  35.   {
  36.       temp = la_cola.extraer();
  37.       cout << "?) " << temp << " \n";
  38.  
  39.   }
  40. }
  41. /* FIN DE main.cpp */
  42.  
  43. /* INICIO DE colaint.h */
  44. #ifndef COLAINT_H
  45. #define COLAINT_H
  46.  
  47. #define MAX 1000
  48.  
  49. class ColaInt
  50. {
  51.     public:
  52.         ColaInt();
  53.         ~ColaInt();
  54.         void agregar(int elemento);
  55.     int extraer();
  56.     bool vacia();
  57.         bool vacio();
  58.     protected:
  59.    
  60.     private:
  61.         int los_datos[MAX];
  62.             int primero, ultimo;
  63. };
  64.  
  65. #endif // COLAINT_H
  66. /* FIN DE colaint.h */
  67.  
  68. /* INICIO DE colaint.cpp */
  69. #include "colaint.h"
  70.  
  71. ColaInt::ColaInt()
  72. {
  73.     this->primero = 0;
  74.     this->ultimo  = 0;
  75. }
  76.  
  77. ColaInt::~ColaInt()
  78. {
  79.     //destructor
  80. }
  81.  
  82. void ColaInt::agregar(int elemento)
  83. {
  84.     los_datos[this->ultimo] = elemento;
  85.   this->ultimo++;
  86. }
  87.  
  88. int ColaInt::extraer()
  89. {
  90.     int temp = los_datos[this->primero];
  91.     this->primero++;
  92.     return temp;
  93. }
  94.  
  95. bool ColaInt::vacia()
  96. {
  97.     if (this->primero==this->ultimo)
  98.   {
  99.     return true;
  100.   }
  101.   else
  102.   {
  103.     return false;
  104.   }
  105.   this->primero = 0;
  106.   this->ultimo  = 0;
  107. }
  108.  
  109. bool ColaInt::vacio()
  110. {
  111.   return this->vacia();
  112. }
  113.  
  114. /* FIN DE colaint.cpp */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement