From the course: Complete Guide to C++ Programming Foundations

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Solution: Virtual pet schedule

Solution: Virtual pet schedule

(upbeat intro music) (music ends) - [Instructor] For this challenge, your task was to write the ManagePetSchedule function, which takes a list of initial activities and a list of operations to perform on the schedule of your pet's day. Let me show you my solution. Starting at line 28, I copied the initialActivities argument into the local schedule deque. Then in line 30, we have a ranged for Loop that traverses the operations vector with the op variable, which represents each pair in the vector. Next, we have a switch statement to decide what to do based on the command in the current pair. That's what op.first is, an operation enumerator. The rest is very straightforward. For the add operations, we use the push_front or push_back functions on the schedule to insert the second element in the pair, which is another pair with the schedule entry. As for the remove operations, we use the corresponding pop function, and we don't even look at the second element of the pair, but we need to…

Contents