In this problem, you are asked to implement some functions of a queue with random access.
You are asked to implement a class IQueue
with the following functions:
IQueue::IQueue()
: Default constructor. Already implemented.IQueue::IQueue(IQueue const& rhs)
: Copy constructor. Construct a new queue with the same elements as rhs
.IQueue::IQueue(IQueue&& rhs)
: Move constructor. Construct a new queue by moving the elements from rhs
.IQueue& IQueue::operator=(IQueue const& rhs)
: Copy assignment operator. Assign the elements of rhs
to the current queue.IQueue& IQueue::operator=(IQueue&& rhs)
: Move assignment operator. Move the elements from rhs
to the current queue.IQueue::~IQueue()
: Destructor.void IQueue::Push(int val)
: Push val
to the back of the queue.void IQueue::Pop(void)
: Pop the front element of the queue.int& IQueue::Front(void)
: Return a reference to the front element of the queue.int& IQueue::operator[](size_t pos)
: Return a reference to the element at index pos
of the queue. It is guaranteed that pos
is in the range \([0, size)\), so you don't need to check for out of range errors.int& IQueue::At(size_t pos)
: Return a reference to the element at index pos
of the queue. If pos
is out of range, throw an std::out_of_range
exception with the message "Out of range".void IQueue::Swap(IQueue& rhs)
: Swap the elements of the current queue with rhs
.bool IQueue::Empty(void)
: Return true
if the queue is empty, false
otherwise.size_t IQueue::Size(void)
: Return the number of elements in the queue. Already implemented.void IQueue::DoubleCapacity(void)
: Double the capacity of the queue.Note: The capacity
of the queue is the maximum number of elements that can be stored in data
. The size
of the queue is the number of elements currently in data
. When Push
is called and the size
of the queue is equal to the capacity
, you should double the capacity
of the queue.
Warning: You should use C++11 or later versions, or else you will get Compile Error! The move constructor and move assignment operator are added in C++11.
Hints:
What is an lvalue?
Value categories
Move Constructors in C++ with Examples
std::move
This is a partial judge problem, input and output are handled by main.cpp
.
IQueue::Pop(void)
and IQueue::Front(void)
, the queue is not empty.IQueue::operator[](int pos)
, the index pos
is in the range \([0, size)\).This is a partial judge problem, input and output are handled by main.cpp
.