首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在c中与vector<string>进行比较和排序

如何在c中与vector<string>进行比较和排序
EN

Stack Overflow用户
提问于 2012-12-11 01:05:10
回答 1查看 142关注 0票数 0

我有两个由蛋白质pdb id组成的载体,如1A3BA,3B5RE,1WYX5。我想比较一下这两个向量中的蛋白质列表是否相同。有什么不同呢?我试着在C++中使用stl算法,但是总是有段错误!有没有人能告诉我出什么事了?我也不太确定排序算法,但是anyway..No不管我放不放排序,代码都有问题……

代码语言:javascript
复制
vector<string> pdb_b_list;
vector<string> pdb_a_list;
vector<string> intset;
vector<string>::iterator im;

           sort(pdb_a_list.begin(),pdb_a_list.end());
           sort(pdb_b_list.begin(),pdb_a_list.end());  

         if (includes(pdb_a_list.begin(), pdb_a_list.end(), pdb_b_list.begin(), pdb_b_list.end())){
            cout << "a includes b"<<endl;
             cnt_s++;
              }

       else if (includes(pdb_b_list.begin(), pdb_b_list.end(), pdb_a_list.begin(), pdb_a_list.end()) ){
             cout <<"b includes a" <<endl;
             cnt_s++;
              }
         else      {
           cout << "different proteins  in the sets" <<endl;
           cnt_d++;
           //sort(pdb_a_list.begin(),pdb_a_list.end());
          // sort(pdb_b_list.begin(),pdb_a_list.end());
           im = set_intersection(pdb_a_list.begin(),pdb_a_list.end(),pdb_b_list.begin(),pdb_a_list.end(), intset.begin());
           cout <<" the intersetion has \t" <<int(im- intset.begin())<<"elements" <<endl;

                   }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-11 01:07:51

看看如何对第二个向量进行排序:

代码语言:javascript
复制
sort(pdb_b_list.begin(),pdb_a_list.end());  

您插入了错误的结束索引,它应该是pdb_**b**_list.end(),因此是段错误。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13805625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档