c++list运用

来源:互联网 发布:java方法重写 编辑:程序博客网 时间:2024/04/30 18:58


//temp tp1, tp2;
//tp1.a = 1;
//tp1.name = "tp1name";
//tp2.a = 2;
//tp2.name = "tp2name";
//vector<temp> vt;
//vt.push_back(tp1);
//vt.push_back(tp2);
//for (vector<temp>::iterator it = vt.begin(); it != vt.end(); it++)
//{
// cout << ((temp)*it).name << endl;
//}




list<int> one(5, 2);
int stuff[5] = { 1, 2, 3, 8, 6 };
list<int> two;
two.insert(two.begin(), stuff, stuff + 5);
int more[6] = { 6, 4, 2, 4, 6, 5 };
list<int> three(two);
three.insert(three.end(), more, more + 6);


int resum = accumulate(two.begin(), two.end(), 0); //list中元素相加




cout << resum << endl;


/*for (list<int>::iterator it  = two.begin(); it != two.end(); it++)
{
cout << *it << endl;
}
*/
list<int>::iterator it;
it = max_element(two.begin(), two.end());   //list取最大元素
cout << *it << endl;
原创粉丝点击