首页 > 代码库 > 判断两个vector是否相等
判断两个vector是否相等
转载:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=26354188&id=3198604
1 #include <iostream> 2 #include <vector> 3 4 using namespace std; 5 6 int main() 7 { 8 vector<int> ivec1, ivec2; 9 int ival,iva2;10 11 cout<<"Enter numbers for vector1(-1 to end): "<<endl;12 cin >> ival;13 while (ival != -1)14 {15 ivec1.push_back(ival);16 cin >> ival;17 }18 cout<<"Enter numbers for vector2(-1 to end): "<<endl;19 cin >> ival;20 while (ival != -1)21 {22 ivec2.push_back(ival);23 cin >> iva2;24 }25 26 if (ivec1.size() != ivec2.size())27 cout<<"Vector1 is not equal to vector2."<<endl;28 else if(ivec1.size() == 0)29 cout<<"Vector1 is equal to vector2"<<endl;30 else31 {32 vector<int>::iterator iter1, iter2;33 iter1 = ivec1.begin();34 iter2 = ivec2.begin();35 while (iter1 != ivec1.end() && iter2 != ivec2.end()36 && *iter1 == *iter2)37 {38 ++iter1;39 ++iter2;40 }41 if(iter1 == ivec1.end())42 cout<<"Vector1 is equal to vector2."<<endl;43 else44 cout<<"Vector1 is not equal to vector2."<<endl;45 }46 return 0;47 }
判断两个vector是否相等
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。