c++,STL部分的问题Now you have to implement a class named Expanded

c++,STL部分的问题

Now you have to implement a class named ExpandedVector, with only one method my_reverse.

This method simply reverse the order of elements in the sequence of a vector.

For example:

v.push_back(1); // 1

v.push_back(2); // 1 2

v.my_reverse(); // 2 1

For your convenience, the data type of the elements is set to be ints.

要求写ExpandedVector.h的内容


独苍然而泣下 1年前 已收到1个回答 举报

无影天光 幼苗

共回答了14个问题采纳率:92.9% 举报

// ExpandedVector.h
#include
class ExpandedVector: public vector{
public:
void my_reverse(){
int N = size();
for(int i=0; i std::swap(at(i), at(N-1-i));
}
};

1年前

9
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 0.832 s. - webmaster@yulucn.com