开发者

Container needed for C++

开发者 https://www.devze.com 2023-02-03 00:42 出处:网络
I need a container (like array)for integers in such a way that given x and y and z ,which has to be inserted between x and y it will be possible to insert z betwee开发者_运维百科n them.And given x and

I need a container (like array)for integers in such a way that given x and y and z ,which has to be inserted between x and y it will be possible to insert z betwee开发者_运维百科n them.And given x and y ,get if x is placed left to the y.


Well you could use an std::set<int>. It will always keep your elements ordered.


Well, use vector.

Something like this.

vector<int> v;
v.push_back(x);
v.push_back(y);
vector<int> :: iterator it = v.begin();
v.insert(it + 1, z);

Have a look here: http://www.cplusplus.com/reference/stl/vector/insert/

0

精彩评论

暂无评论...
验证码 换一张
取 消