Queue Flashcards
1
Q
Queue enqueue
A
void enqueue(T value) { if (isFull()) { cout << "Queue is already full" << endl; return; } else if (isEmpty()) { first = 0; last = 0; queue[last] = value; } else { last = (last + 1) % MAXSIZE; queue[last] = value; } }
2
Q
Queue dequeue
A
void dequeue() { if (isEmpty()) { cout << "Queue is empty " << endl; return; } else if (first == last) { first = -1; last = -1; } else { first = (first + 1) % MAXSIZE; } }
3
Q
Queue peekFront
A
T peekFront() const { if (isEmpty()) { cout << "Eile tuscia. Nera pirmo elemento." << endl; return T(); } else { return queue[first]; } }
4
Q
Queue peekBack
A
T peekBack() const { if (isEmpty()) { cout << "Eile tuscia. Nera paskutinio elemento." << endl; return T(); } else { return queue[last]; } }
5
Q
Queue isEmpty
A
bool isEmpty() const { return first == -1; }
6
Q
Queue isFull
A
bool isFull() const { return (last + 1) % MAXSIZE == first; }
7
Q
Queue clear
A
void clear() { first = -1; last = -1; }
8
Q
Queue display
A
template <typename T> void display(const Queue<T>& q) { if (q.isEmpty()) { cout << "Queue is empty" << endl; return; } Queue<T> qcopy = q; while (!qcopy.isEmpty()) { cout << qcopy.front() << " "; qcopy.dequeue(); } cout << endl; }
9
Q
Queue reverse
A
template <typename T> void reverse(Queue<T>& q) { if (q.isEmpty()) { cout << "Eile yra tuscia." << endl; return; } stack<T> s; while (!q.isEmpty()) { s.push(q.front()); q.dequeue(); } while (!s.empty()) { q.enqueue(s.top()); s.pop(); } }