Deque pushBack
void pushBack(T value)
{
if (isFull())
{
cout << "Deque is full." << endl;
return;
}
else if (isEmpty())
{
frontIndex = 0;
backIndex = 0;
}
else
{
backIndex = (backIndex + 1) % MAXSIZE;
}
deque[backIndex] = value;
}Deque pushFront
void pushFront(T value)
{
if (isFull())
{
cout << "Deque is full" << endl;
return;
}
else if (isEmpty())
{
frontIndex = 0;
backIndex = 0;
}
else
{
frontIndex = (frontIndex - 1 + MAXSIZE) % MAXSIZE;
}
deque[frontIndex] = value;
}Deque popFront
void popFront()
{
if (isEmpty())
{
cout << "Deque is empty." << endl;
return;
}
else if (frontIndex == backIndex)
{
frontIndex = -1;
backIndex = -1;
}
else
{
frontIndex = (frontIndex + 1) % MAXSIZE;
}
}Deque popBack
void popBack()
{
if (isEmpty())
{
cout << "Deque is empty
" << endl;
return;
}
else if (frontIndex == backIndex)
{
frontIndex = -1;
backIndex = -1;
}
else
{
backIndex = (backIndex - 1 + MAXSIZE) % MAXSIZE;
}
}Deque peekFront
T front() const
{
if (isEmpty())
{
cout << "Deque is empty." << endl;
return T();
}
return deque[frontIndex];
}Deque peekBack
T back() const
{
if (isEmpty())
{
cout << "Deque is empty." << endl;
return T();
}
return deque[backIndex];
}Deque isEmpty
bool isEmpty() const
{
return frontIndex == -1;
}Deque isFull
bool isFull() const
{
return (backIndex + 1) % MAXSIZE == frontIndex;
}Deque clear
void clear()
{
frontIndex = -1;
backIndex = -1;
}Deque display
template <typename T>
void display(const Deque<T>& d)
{
if (d.isEmpty())
{
cout << "Deque is empty" << endl;
return;
}
Deque<T> temp = d;
while (!temp.isEmpty())
{
cout << temp.front() << " ";
temp.popFront();
}
cout << endl;
}Deque reverse
template <typename T>
void reverse(Deque<T>& d)
{
if (d.isEmpty())
{
cout << "Deque is empty" << endl;
return;
}
stack<T> s;
while (!d.isEmpty())
{
s.push(d.front());
d.popFront();
}
while (!s.empty())
{
d.pushBack(s.top());
s.pop();
}
}