Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Queue {
- //atributo
- int size;
- int* queue;
- //construtor
- public:
- Queue() {
- size = 0;
- queue = new int[100];
- }
- //metodos
- 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 - 1; i++) {
- cout<<queue[i]<<" <- ";
- }
- cout <<endl;
- }
- public:
- void add()
- {
- item = 0;
- for (int x = 0; x < size - 1 ; x++) {
- queue[x] = queue[x - 1];
- }
- size++;
- }
- };
- int main() {
- Queue q;
- q.add(42); q.add(2); q.add(8); q.add(1);
- q.print();
- q.remove();
- q.add(128);
- q.print();
- q.remove();
- q.remove();
- q.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement