课程: Complete Guide to C++ Programming Foundations
免费学习该课程!
今天就开通帐号,24,100 门业界名师课程任您挑!
Solution: Vector manipulation - C++教程
课程: 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…
内容
-
-
-
-
-
-
(已锁定)
Arrays7 分钟 27 秒
-
Pointers7 分钟 59 秒
-
(已锁定)
How arrays and pointers are related5 分钟 14 秒
-
(已锁定)
Using objects with pointers10 分钟 56 秒
-
(已锁定)
The vector class5 分钟
-
(已锁定)
Using objects with vectors6 分钟 29 秒
-
(已锁定)
References4 分钟 56 秒
-
(已锁定)
C strings11 分钟 16 秒
-
(已锁定)
The string class4 分钟 14 秒
-
(已锁定)
Solution: Vector manipulation2 分钟
-
(已锁定)
-
-
-
-
-
-