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: Vector manipulation - C++ Tutorial
From the course: Complete Guide to C++ Programming Foundations
Solution: Vector manipulation
(bright electronic music) - [Instructor] For this challenge, your task was to write the code for the SelectKeyPoints function to return a downsized version of the incoming vector. You were given a vector of integers and an index to pick the middle element in the downsized output vector. Let me show you my solution. First, in line 14, I used the push_back function on the result vector to insert the value at the beginning of the distances vector. Remember, since begin returns and iterator, I must de-reference it with the indirection asterisk operator. Then, in line 15, I'm doing the same, but I'm indexing the vector with the square brackets operator. The index is checkpointIndex. And lastly, in line 16, I could have done the same as with the begin function, but using the end function and going back by one position. However, I decided to use the back function, which returns the last element in the vector. This is not an iterator, but the integer at the last position in the vector. That's…
Contents
-
-
-
-
-
-
(Locked)
Arrays7m 27s
-
Pointers7m 59s
-
(Locked)
How arrays and pointers are related5m 14s
-
(Locked)
Using objects with pointers10m 56s
-
(Locked)
The vector class5m
-
(Locked)
Using objects with vectors6m 29s
-
(Locked)
References4m 56s
-
(Locked)
C strings11m 16s
-
(Locked)
The string class4m 14s
-
(Locked)
Solution: Vector manipulation2m
-
(Locked)
-
-
-
-
-
-