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;
		}
	}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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;
		}
	}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Queue peekFront

A
	T peekFront() const
	{
		if (isEmpty())
		{
			cout << "Eile tuscia. Nera pirmo elemento." << endl;
			return T();
		}
		else
		{
			return queue[first];
		}
	}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Queue peekBack

A
	T peekBack() const
	{
		if (isEmpty())
		{
			cout << "Eile tuscia. Nera paskutinio elemento." << endl;
			return T();
		}
		else
		{
			return queue[last];
		}
	}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Queue isEmpty

A
    bool isEmpty() const
    {
        return first == -1;
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Queue isFull

A
	bool isFull() const
	{
		return (last + 1) % MAXSIZE == first;
	}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Queue clear

A
	void clear()
	{
		first = -1;
		last = -1;
	}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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();
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly