c++ 杂

---恢复内容开始---

priority_queue<int> q;

q.top();

q.push();

q.pop();

//////////////////////////////////////////////////////////////////////////////

// 查找vec中最长字符串

vector<string> vec;

vector<string>::iterator it =

max_element(vec.begin().vec.end(),comp);

bool comp(const  string &s1,const string &s2 )

{

  return s1.size() < s2.size();

}

/////////////////////////////////////////////////////////////////////////////////

int min = *std::min_element(vec.begin(), vec.end());

 

///////////////////////////////////////////////////////////////////////////////////

vector<string> vec;

 it = std::find_if(vec.begin(), vec.end(), isShorter);

bool isShorter(const string &s)
{
    return s.size() < 6;
}

 ///////////////////////////////////////////////////////////////////////////////////

vector中的元素复制到lst中;

  vector<string> vec;
    vec.push_back("beijing");
    vec.push_back("changchun");


    list<string> lst;
//两种复制方式,正序复制和逆序复制
    std::copy(vec.begin(), vec.end(), back_inserter(lst)); //push_back

 std::copy(vec.begin(), vec.end(), front_inserter(lst)); //push_front

/////////////////////////////////////////////////////////////////////////////////////

//一种无名函数的写法及使用

// [](const string &s) { cout << s << " "; } 这个无名函数的功能与下面的print函数功能相同

//void print(const string &s )

//{

//   cout << s << " " ;

//}

 

 

 

 for_each(vec.begin(), vec.end(), [](const string &s) { cout << s << " "; });

///////////////////////////////////////////////////////////////////////////////////////////////////

 

posted @ 2014-11-11 03:29  schnappi  阅读(173)  评论(0编辑  收藏  举报