+ 1

Me podrían ayudar a resolver el fin de módulo 5 el de gestión de colas por fa

27th Apr 2021, 3:43 AM
Nicole Tatiana Beltrán Suárez
Nicole Tatiana Beltrán Suárez - avatar
6 Antworten
+ 1
Espero que te sirva de guía #include <iostream> using namespace std; template <class T> class Queue{ private : int size; T* queue; public: Queue() { size = 0; queue = new T [100]; } void add(T data) { queue[size] = data; size++; } void remove() { if (size == 0) { cout << "Queue is empty"<<endl; return; } else { for (int i = 0; i < size - 1; i++) { queue[i] = queue[i + 1]; } size--; } } void print() { if (size == 0) { cout << "Queue is empty"<<endl; return; } for (int i = 0; i < size; i++) { cout<<queue[i]<<" <- "; } cout << endl; } }; int main() { Queue<int> q1; q1.add(42); q1.add(2); q1.add(8); q1.add(1); q1.print(); Queue<string> q2; q2.add("Dave"); q2.add("John"); q2.add("Amy"); q2.print(); return 0; }
28th Apr 2021, 4:19 AM
Luis Andrés Valido Fajardo 🇨🇺
Luis Andrés Valido Fajardo 🇨🇺 - avatar
+ 1
// esta es la verdadera solución #include <iostream> using namespace std; template <class T> class Queue{ private : int size; T* queue; public: Queue() { size = 0; queue = new T [100]; } void add(T data) { queue[size] = data; size++; } void remove() { if (size == 0) { cout << "Queue is empty"<<endl; return; } else { for (int i = 0; i < size - 1; i++) { queue[i] = queue[i + 1]; } size--; } } void print() { if (size == 0) { cout << "Queue is empty"<<endl; return; } for (int i = 0; i < size; i++) { cout<<queue[i]<<" <- "; } cout << endl; } }; int main() { Queue<int> q1; q1.add(42); q1.add(2); q1.add(8); q1.add(1); q1.print(); Queue<int>q2; q2.add(2); q2.add(8); q2.add(1); q2.add(128); q2.print(); Queue<int>q3; q3.add(1);q3.add(128); q3.print(); return 0; }
20th Dec 2021, 9:06 PM
Jhon Palmieri Meza
Jhon Palmieri Meza - avatar
0
//tu código va aqui void add(int n) { queue[size] = n; size++; } Asi Cree la funcion Add Espero que te sirva !
12th Oct 2021, 1:08 AM
Jhon Stiven Caicedo Mosquera
Jhon Stiven Caicedo Mosquera - avatar
0
Hola buenas noches
19th Nov 2021, 6:36 AM
Perla Hernández Guevara
Perla Hernández Guevara - avatar
0
Me puedes ayudar en sacar el código
19th Nov 2021, 6:36 AM
Perla Hernández Guevara
Perla Hernández Guevara - avatar
0
Espero te sirva //tu código va aquí Queue operator+(Queue obj) { Queue result; result.size = this ->size; result.queue = this ->queue; int length=obj.size; int n=0; while(n<length) { result.add(obj.queue[n]); n++; } return result; }
23rd Aug 2022, 2:43 PM
Janer Leal Hernandez
Janer Leal Hernandez - avatar