Now Google is hiring! They have many opening positions, where some positions are for new graduates and some are for experienced ones. A lot of resumes have been received. We assume new graduated students can only submit to positions for new graduates and people with working experience can only submit to positions for experienced ones. The Google HR (Human Resources) department wants to evaluate these resumes, and you are asked to implement a resume container for storing and reviewing resumes submitted to each position.
The Google HR department raised the following requirements:
"Jack"
;<"Yang", "HKUST">
. We use the std::pair
container provided in STL to represent it (a description of std::pair
can be found here).deque
(double end queue) is the most appropriate data structure to implement the resume container. As shown in the figure, a deque
is a sequence container that allows adding/removing elements from both the front and the back end.
Deque
has been implemented in C++ Standrad Template Library (STL), related information can be found in std::deque.
In this lab, you will implement your own version of deque
using a doubly linked list. The doubly linked list is a data structure that generalizes the linked list, where every node in a doubly linked list has a pointer to the next node and also a pointer to the previous node.
We have implement a skeleton of the deque
data structure in source files, you have to finish the TODOs left in the code.
The descriptions of classes and members in classes are as follows:
class BiLNode
: Class of nodes in the doubly linked list.
T data
:BiLNode *next
:BiLNode *prev
:BiLNode(T input)
:class Deque
:
BiLNode *head
:BiLNode *tail
:int size
:void push_back(const T& value)
:void push_front(const T& value)
:T pop_back()
:T pop_front()
:void clear()
:operator==
(TODO):operator=
(TODO):operator+
(TODO):operator<<
(TODO):operator<<
is alreay overloaded for all types of elements.
std::pair
: here.
deque.h
:
operator==
operator=
operator+
operator<<
main.exe
, check with the expected output below:Create resume container for position: C++ developer. Applicants of C++ developer: [(James, HKUST)<-->(Yang, HKUST)<-->(Amelia, CUHK)<-->(David, HKU)] Create resume container for position: C developer. Applicants of C developer: [(Tony, HKUST)<-->(Oliver, PolyU)<-->(Wang, CUHK)] Create resume container for position: AI researcher (experienced) Applicants of AI researcher (experienced): [Michael<-->Noah<-->Isabella] Reviewing resumes for C++ developer. Remaining resumes for C++ developer: [(Amelia, CUHK)<-->(David, HKU)] C++ developer position is closed, add resumes to C developer container. Applicants of C developer before adding: [(Tony, HKUST)<-->(Oliver, PolyU)<-->(Wang, CUHK)] Applicants of C developer after adding: [(Tony, HKUST)<-->(Oliver, PolyU)<-->(Wang, CUHK)<-->(Amelia, CUHK)<-->(David, HKU)] Make a copy of AI researcher resumes. Copy of AI researcher resumes: [Michael<-->Noah<-->Isabella] Is the copy equivalent to the orign? Yes Is the copy still equivalent to the orign? No
Question: Can we return a deque object by value when overloading operator+?
Answer:
Usually, when we return a temporary object created in a function by value, the copy constructor will be called to make a copy of the object, and the original temporary object will be destroyed when the function is finished. In this case, if the object holds some dynamically allocated memory and the copy constructor only does shallow copy (as the deque class does), it will cause errors.
But since C++11, the copy constructor will be omitted in many pass-by-value semantics because of a feature named copy elision (Please also see p18 in lecture notes of constructor & destructor). In the case of this lab, we can safely return a deque object by value when overloading operator+ and the copy constructor will not be called. But since copy elision is not a mandatory feature until C++17, we should still implement the copy constructor carefully in normal cases.
The due date and time will be 10-min after your lab session. You are supposed to upload the following files in an archive to ZINC:
- deque.hYou can submit your codes multiple times by the deadline. Only the last submission will be graded.