Container needed for C++
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/
精彩评论