Advertisement
Guest User

ColaEstática

a guest
Sep 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #ifndef __HEADER_H__
  2. #define __HEADER_H__
  3. #include "Node.h"
  4. #include <iostream>
  5. #include <functional>
  6. typedef unsigned int uint;
  7. template <typename T>
  8. class Cola
  9. {
  10. public:
  11. T* arr;
  12. uint numEl;
  13. uint fin;
  14. uint ini;
  15. uint elmUs;
  16. Cola() : fin(0), ini(0), elmUs(0)
  17. {
  18. numEl = 10;
  19. arr = new T[numEl];
  20. }
  21. ~Cola() { delete[] arr; }
  22. void agregar(T elem)
  23. {
  24. if (fin == 10)
  25. fin = 0;
  26.  
  27. if (elmUs < 10)
  28. {
  29. arr[fin] = elem;
  30. fin++;
  31. ++elmUs;
  32. }
  33.  
  34. }
  35.  
  36. void eliminar()
  37. {
  38. if (elmUs != 0)
  39. {
  40. ini++;
  41. if (ini == 10)
  42. ini = 0;
  43. elmUs--;
  44. }
  45. }
  46.  
  47. };
  48.  
  49. #endif
  50.  
  51.  
  52. #include "Header.h"
  53. int main()
  54. {
  55. Cola<int>* cl = new Cola<int>();
  56. cl->agregar(1);
  57. cl->agregar(2);
  58. cl->agregar(3);
  59. cl->agregar(4);
  60. cl->agregar(5);
  61. cl->agregar(6);
  62. cl->eliminar();
  63. cl->agregar(7);
  64. cl->agregar(8);
  65. cl->agregar(9);
  66. cl->agregar(10);
  67. cl->agregar(11);
  68. cl->agregar(12);
  69.  
  70. uint pos = cl->ini;
  71. for (int i = 0; i < cl->elmUs; ++i, ++pos)
  72. {
  73. if (pos == 10)
  74. {
  75. pos = 0;
  76. }
  77. std::cout << cl->arr[pos] << " -> ";
  78. }
  79.  
  80.  
  81. delete cl;
  82. std::cin.get();
  83. return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement