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 - C++ Tutorial
From the course: Complete Guide to C++ Programming Foundations
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
-
-
-
-
-
-
-
-
-
-
(Locked)
Understanding templates3m 1s
-
(Locked)
Template functions3m 5s
-
(Locked)
Template classes2m 39s
-
(Locked)
Overview of the STL2m 16s
-
(Locked)
Queues and stacks4m 19s
-
(Locked)
Advanced concepts: Iterators6m 10s
-
(Locked)
Advanced concepts: Algorithms3m 27s
-
(Locked)
Solution: Virtual pet schedule1m 48s
-
(Locked)
-
-