Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <array>
- #include <iostream>
- using namespace std;
- struct pila {
- array<int,10> arr;
- int count = 0;
- };
- struct cola {
- array <int,5> arr;
- int front = 0;
- int rear = 0;
- int cant = 0;
- };
- pila& push (pila& p, int v)
- {
- p.arr.at(p.count) = v;
- p.count++;
- return p;
- }
- pila& pop (pila& p, int& v)
- {
- v = p.arr.at(p.count - 1);
- p.count--;
- return p;
- }
- cola& enqueue (cola& q, int v)
- {
- if (q.cant == 5)
- {
- cout << "Cola llena." << endl;
- return q;
- }
- else
- {
- q.arr.at(q.rear) = v;
- q.rear = (q.rear+1)%5;
- q.cant++;
- return q;
- }
- }
- cola& dequeue (cola& q, int& v)
- {
- if (q.cant == 0)
- {
- cout << "Cola vacia." << endl;
- return q;
- }
- else
- {
- v = q.arr.at(q.front);
- q.front = (q.front+1)%5;
- q.cant--;
- return q;
- }
- }
- void mostrar_cola (cola& q)
- {
- cout << "F a R: ";
- for (int i=0; i<q.cant; i++)
- cout << q.arr.at((q.front+i)%5) << ' ';
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement