Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HEADER:
- #ifndef QUEUE_H_INCLUDED
- #define QUEUE_H_INCLUDED
- class Queue
- {
- int head; //ukazatel na zacatek
- int tail; //ukazatel na konec
- int capacity; //maximalni pocet prvku
- int *data; //data
- public:
- Queue(int size);
- // Queue(Queue &original);
- ~Queue();
- void addLast(int i);
- void deleteFirst(int i);
- int getFirst () const;
- bool isEmpty() const;
- bool isFull() const;
- };
- #endif // QUEUE_H_INCLUDED
- .CPP soubor
- #include "queue.h"
- Queue::Queue(int size)
- : head(-1), tail(-1), capacity(size), data(new int[capacity])
- {
- //telo se provede az po inicializacni casti
- }
- Queue::~Queue(){//destruktor
- delete [] data; //potreba uvest, ze se jedna o pole
- }
- void Queue::addLast(int i){
- tail++;
- if (tail > capacity - 1)
- tail = 0;
- data[tail]=i;
- }
- void Queue::deleteFirst(int i){
- // data[head] (je potreba ta data nejak vymazat?
- head++;
- if (head > capacity - 1)
- head = 0;
- }
- int Queue::getFirst () const{
- return data[head];
- }
- bool Queue::isEmpty() const{
- return (tail == -1);
- }
- bool Queue::isFull() const{
- return (head == tail);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement