Advertisement
Guest User

queue

a guest
Oct 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. HEADER:
  2.  
  3. #ifndef QUEUE_H_INCLUDED
  4. #define QUEUE_H_INCLUDED
  5.  
  6. class Queue
  7. {
  8.     int head; //ukazatel na zacatek
  9.     int tail; //ukazatel na konec
  10.     int capacity; //maximalni pocet prvku
  11.     int *data; //data
  12. public:
  13.     Queue(int size);
  14. //    Queue(Queue &original);
  15.     ~Queue();
  16.     void addLast(int i);
  17.     void deleteFirst(int i);
  18.     int getFirst () const;
  19.  
  20.     bool isEmpty() const;
  21.     bool isFull() const;
  22.  
  23. };
  24. #endif // QUEUE_H_INCLUDED
  25.  
  26. .CPP soubor
  27.  
  28. #include "queue.h"
  29.  
  30. Queue::Queue(int size)
  31. : head(-1), tail(-1), capacity(size), data(new int[capacity])
  32. {
  33.     //telo se provede az po inicializacni casti
  34. }
  35.  
  36. Queue::~Queue(){//destruktor
  37.     delete [] data; //potreba uvest, ze se jedna o pole
  38. }
  39.  
  40. void Queue::addLast(int i){
  41.     tail++;
  42.     if (tail > capacity - 1)
  43.         tail = 0;
  44.     data[tail]=i;
  45. }
  46.  
  47. void Queue::deleteFirst(int i){
  48. //    data[head] (je potreba ta data nejak vymazat?
  49.     head++;
  50.     if (head > capacity - 1)
  51.         head = 0;
  52. }
  53.  
  54. int Queue::getFirst () const{
  55.     return data[head];
  56. }
  57.  
  58. bool Queue::isEmpty() const{
  59.     return (tail == -1);
  60. }
  61.  
  62. bool Queue::isFull() const{
  63.     return (head == tail);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement