我打算建立链接以识别两个 vector 的关联。 假设我们有两个 vector :
vector1 <seg1, seg2, seg3>
vector2 <pic1, pic2, pic3,pic4>
关联假设如下:
seg1->(pic1, pic2) seg2->(pic1,pic2) seg3->pic3 //from vector1 side
pic1->(seg1, seg2) pic2->(seg1,seg2) pic3->seg3 pic4->nothing //from vector2 side
我想要的是知道哪个 seg 与图片的哪个 indexNums 相关联,图片也是如此。我只关注两个 vector 中的位置编号,并不关心这两个 vector 的元素内容是什么。我所做的是设计如下结构:
Struct
{
int indexNum;
Bool type; //seg or pic
addlink(indexNum); //add a link to another Struct, and the type should be opposite.
removelink(indexNum); //remove a link from a given indexNum
getLinks(); //return all of links, the return should be vector<Struct*>?
}
我觉得不好,对协会来说不清楚。有没有更好的方法为这两个 vector 建立链接?
最佳答案
Boost.Bimap旨在解决此类问题。
关于c++ - 在两个 vector 中的元素之间创建链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17054082/