青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

麒麟子

~~

導航

<2013年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

統(tǒng)計

常用鏈接

留言簿(12)

隨筆分類

隨筆檔案

Friends

WebSites

積分與排名

最新隨筆

最新評論

閱讀排行榜

評論排行榜

[導入]List methods



Table 6.12. Constructors and Destructor of Lists Operation Effect
list<Elem> c Creates an empty list without any elements
list<Elem> c1(c2) Creates a copy of another list of the same type (all elements are copied)
list<Elem> c(n) Creates a list with n elements that are created by the default constructor
list<Elem> c(n,elem) Creates a list initialized with n copies of element elem
list<Elem> c (beg,end) Creates a list initialized with the elements of the range [beg,end)
c.~list<Elem>() Destroys all elements and frees the
memory

Table 6.13. Nonmodifying Operations of Lists Operation Effect
c.size() Returns the actual number of elements
c. empty () Returns whether the container is empty (equivalent to size()==0, but might be faster)
c.max_size() Returns the maximum number of elements possible
c1 == c2 Returns whether c1 is equal to c2
c1 != c2 Returns whether c1 is not equal to c2 (equivalent to ! (c1==c2))
c1 < c2 Returns whether c1 is less than c2
c1 > c2 Returns whether c1 is greater than c2 (equivalent to c2<c1)
c1 <= c2 Returns whether c1 is less than or equal to c2 (equivalent to ! (c2<c1) )
c1 >= c2 Returns whether c1 is greater than or equal to c2 (equivalent to ! (c1<c2))

Table 6.14. Assignment Operations of Lists Operation Effect
c1 = c2 Assigns all elements of c2 to c1
c.assign(n,elem) Assigns n copies of element elem
c.assign(beg,end) Assigns the elements of the range [beg,end)
c1.swap(c2) Swaps the data of c1 and c2
swap(c1,c2) Same (as global function)

Table 6.15. Direct Element Access of Lists Operation Effect
c.front() Returns the first element (no check whether a first element exists)
c.back() Returns the last element (no check whether a last element exists)

Table 6.16. Iterator Operations of Lists Operation Effect
c.begin() Returns a bidirectional iterator for the first element
c.end() Returns a bidirectional iterator for the position after the last element
c.rbegin() Returns a reverse iterator for the first element of a reverse iteration
c.rend() Returns a reverse iterator for the position after the last element of a reverse iteration

Table 6.17. Insert and Remove Operations of Lists Operation Effect
c.insert (pos, elem) Inserts at iterator position pos a copy of elem and returns the position of the new element
c.insert (pos,n, elem) Inserts at iterator position pos n copies of elem (returns nothing)
c. insert (pos, beg,end) Inserts at iterator position pos a copy of all elements of the range [beg,end) (returns nothing)
c.push_back(elem) Appends a copy of elem at the end
c.pop_back() Removes the last element (does not return it)
c.push_front(elem) Inserts a copy of elem at the beginning
c.pop_front () Removes the first element (does not return it)
c. remove (val) Removes all elements with value val
c.remove_if (op) Removes all elements for which op(elem) yields true
c. erase (pos) Removes the element at iterator position pos and returns the position of the next element
c.erase (beg,end) Removes all elements of the range [beg,end) and returns the position of the next element
c. resize (num) Changes the number of elements to num (if size() grows, new elements are created by their default constructor)
c.resize (num, elem) Changes the number of elements to num (if size ( ) grows, new elements are copies of elem)
c. clear () Removes all elements (makes the container empty)

Table 6.18. Special Modifying Operations for Lists Operation Effect
c.unique() Removes duplicates of consecutive elements with the same value
c.unique(op) Removes duplicates of consecutive elements, for which op() yields true
c1.splice(pos,c2) Moves all elements of c2 to c1 in front of the iterator position pos
c1.splice(pos,c2,c2pos) Moves the element at c2pos in c2 in front of pos of list c1 (c1 and c2 may be identical)
c1.splice(pos,c2,c2beg,c2end) Moves all elements of the range [c2beg,c2end) in c2 in front of pos of list c1 (c1 and c2 may be identical)
c.sort() Sorts all elements with operator <
c.sort(op) Sorts all elements with op()
c1.merge(c2) Assuming both containers contain the elements sorted, moves all elements of c2 into c1 so that all elements are merged and still sorted
c1.merge(c2,op) Assuming both containers contain the elements sorted due to the sorting criterion op(), moves all elements of c2 into c1 so that all elements are merged and still sorted according to op()
c.reverse() Reverses the order of all elements

Examples of Using Lists
The following example in particular shows the use of the special member functions for lists:


// cont/list1.cpp

#include <iostream>
#include <list>
#include <algorithm>
using namespace std;

void printLists (const list<int>& 11, const list<int>& 12)
{

cout << "list1: ";
copy (l1.begin(), l1.end(), ostream_iterator<int>(cout," "));
cout << endl << "list2: ";
copy (12.begin(), 12.end(), ostream_iterator<int>(cout," "));
cout << endl << endl;

}

int main()
{

//create two empty lists
list<int> list1, list2;

//fill both lists with elements
for (int i=0; i<6; ++i) {
list1.push_back(i);
list2.push_front(i);
}
printLists(list1, list2);

//insert all elements of list1 before the first element with value 3 of list2
//-find() returns an iterator to the first element with value 3
list2.splice(find(list2.begin(),list2.end(), // destination position
3),
list1); // source list
printLists(list1, list2);

//move first element to the end
list2.splice(list2.end(), // destination position
list2, // source list
list2.begin()); // source position
printLists(list1, list2);

//sort second list, assign to list1 and remove duplicates
list2.sort();
list1 = list2;
list2.unique();
printLists(list1, list2);

//merge both sorted lists into the first list
list1.merge(list2);
printLists(list1, list2);
}


The program has the following output:


list1: 0 1 2 3 4 5
list2: 5 4 3 2 1 0

list1:
list2: 5 4 0 1 2 3 4 5 3 2 1 0

list1:
list2: 4 0 1 2 3 4 5 3 2 1 0 5

list1: 0 0 1 1 2 2 3 3 4 4 5 5
list2: 0 1 2 3 4 5

list1: 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5
list2:


Vector的
//建立一個向量并為之分配內存
std::vector<int> v; // create an empty vector
v.reserve (80); // reserve memory for 80 elements
//建立一個向量,并用默認的構造函數初始化,因此速度較慢
std::vector<T> v(5); // creates a vector and initializes it with five values
// (calls five times the default constructor of type T)


Table 6.2. Constructors and Destructors of Vectors Operation Effect
vector<Elem> c Creates an empty vector without any elements
vector<Elem> c1(c2) Creates a copy of another vector of the same type (all elements are copied)
vector<Elem> c(n) Creates a vector with n elements that are created by the default constructor
vector<Elem> c(n,elem) Creates a vector initialized with n copies of element elem
vector<Elem> c(beg,end) Creates a vector initialized with the elements of the range [beg,end)
c.~vector<Elem>() Destroys all elements and frees the memory

Table 6.3. Nonmodifying Operations of Vectors Operation Effect
c.size() Returns the actual number of elements
c.empty() Returns whether the container is empty (equivalent to size()==0, but might be faster)
c.max_size() Returns the maximum number of elements possible
capacity() Returns the maximum possible number of elements without reallocation
reserve() Enlarges capacity, if not enough yet[7] //如果不夠的話就繼續(xù)分配內存
c1 == c2 Returns whether c1 is equal to c2
c1 != c2 Returns whether c1 is not equal to c2 (equivalent to ! (c1==c2))
c1 < c2 Returns whether c1 is less than c2
c1 > c2 Returns whether c1 is greater than c2 (equivalent to c2<c1)
c1 <= c2 Returns whether c1 is less than or equal to c2 (equivalent to ! (c2<c1))
c1 >= c2 Returns whether c1 is greater than or equal to c2 (equivalent to ! (c1<c2))

Table 6.4. Assignment Operations of Vectors Operation Effect
c1 = c2 Assigns all elements of c2 to c1
c.assign(n,elem) Assigns n copies of element elem
c.assign(beg,end) Assigns the elements of the range [beg,end)
c1.swap(c2) Swaps the data of c1 and c2
swap(c1,c2) Same (as global function)

Table 6.5. Direct Element Access of Vectors Operation Effect
c.at(idx) Returns the element with index idx (throws range error exception if idx is out of range)
c[idx] Returns the element with index idx (no range checking)
c.front() Returns the first element (no check whether a first element exists)
c.back() Returns the last element (no check whether a last element exists)

通過at來訪問元素的時候如果越界會有一個out_of_range異常
用[]重載來訪問的時候只會報錯

Table 6.6. Iterator Operations of Vectors Operation Effect
c.begin() Returns a random access iterator for the first element
c.end() Returns a random access iterator for the position after the last element
c.rbegin() Returns a reverse iterator for the first element of a reverse iteration
c.rend() Returns a reverse iterator for the position after the last element of a reverse iteration

Table 6.7. Insert and Remove Operations of Vectors Operation Effect
c.insert(pos,elem) Inserts at iterator position pos a copy of elem and returns the position of the new element
c.insert(pos,n,elem) Inserts at iterator position pos n copies of elem (returns nothing)
c.insert(pos,beg,end) Inserts at iterator position pos a copy of all elements of the range [beg,end) (returns nothing)
c.push_back(elem) Appends a copy of elem at the end
c.pop_back() Removes the last element (does not return it)
c.erase(pos) Removes the element at iterator position pos and returns the position of the next element
c.erase(beg,end) Removes all elements of the range [beg,end) and returns the position of the next element
c.resize(num) Changes the number of elements to num (if size() grows, new elements are created by their default constructor)
c.resize(num,elem) Changes the number of elements to num (if size() grows, new elements are copies of elem)
c.clear() Removes all elements (makes the container empty)

std::vector<Elem> coll;
...
//remove all elements with value val
coll.erase(remove(coll.begin(),coll.end(),
val),
coll.end());

std::vector<Elem> coll;
...
//remove first element with value val
std::vector<Elem>::iterator pos;
pos = find(coll.begin(),coll.end(),
val);
if (pos != coll.end()) {
coll.erase(pos);
}

vector<bool>有特殊的函數
Table 6.8. Special Operations of vector<bool> Operation Effect
c.flip() Negates all Boolean elements (complement of all bits)
m[idx].flip() Negates the Boolean element with index idx (complement of a single bit)
m[idx] = val Assigns val to the Boolean element with index idx (assignment to a single bit)
m[idx1] = m[idx2] Assigns the value of the element with index idx2 to the element with index idx1

Examples of Using Vectors
The following example shows a simple usage of vectors:


// cont/vector1.cpp

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main()
{

//create empty vector for strings
vector<string> sentence;

//reserve memory for five elements to avoid reallocation
sentence.reserve(5);

//append some elements
sentence.push_back("Hello,");
sentence.push_back("how");
sentence.push_back("are");
sentence.push_back("you");
sentence.push_back("?");

//print elements separated with spaces
copy (sentence.begin(), sentence.end(),
ostream_iterator<string>(cout," "));
cout << endl;

//print ''technical data''
cout << " max_size(): " << sentence.max_size() << endl;
cout << " size(): " << sentence.size() << endl;
cout << " capacity(): " << sentence.capacity() << endl;

//swap second and fourth element
swap (sentence[1], sentence [3]);

//insert element "always" before element "?"
sentence.insert (find(sentence.begin(),sentence.end(),"?"),
"always");

//assign "!" to the last element
sentence.back() = "!";

//print elements separated with spaces
copy (sentence.begin(), sentence.end(),
ostream_iterator<string>(cout," "));
cout << endl;

//print "technical data" again
cout << " max_size(): " << sentence.max_size() << endl;
cout << " size(): " << sentence.size() << endl;
cout << " capacity(): " << sentence.capacity() << endl;

}


The output of the program might look like this:


Hello, how are you ?
max_size(): 268435455
size(): 5
capacity(): 5
Hello, you are how always !
max_size(): 268435455
size(): 6
capacity(): 10

文章來源:http://ly-weiwei.blog.163.com/blog/static/7297528320092311263852

posted on 2009-03-31 13:26 麒麟子 閱讀(81) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發(fā)表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲欧美卡通另类91av| 亚洲免费影视| 看片网站欧美日韩| 欧美自拍偷拍| 亚洲女同同性videoxma| 亚洲午夜高清视频| 亚洲中午字幕| 久久久国产一区二区| 久久国产精品亚洲77777| 亚洲你懂的在线视频| 亚洲一级二级| 欧美一级黄色录像| 久久久久.com| 欧美韩日精品| 国产精品多人| 尤物精品在线| 亚洲午夜在线观看视频在线| 亚洲嫩草精品久久| 久久久久国产精品厨房| 免费欧美日韩| 亚洲免费观看高清在线观看| 一本色道久久88精品综合| 午夜激情亚洲| 欧美成人dvd在线视频| 欧美色区777第一页| 国产色综合久久| 一区二区国产精品| 老色鬼精品视频在线观看播放| 欧美成人精品一区二区三区| 亚洲精品美女在线| 日韩一区二区精品葵司在线| 亚洲欧美在线一区二区| 欧美99在线视频观看| 欧美午夜视频| 亚洲三级视频在线观看| 亚洲一区二区3| 麻豆久久久9性大片| 日韩小视频在线观看专区| 久久国产乱子精品免费女| 亚洲欧美www| 欧美成人精品在线观看| 宅男噜噜噜66一区二区| 免费在线欧美视频| 国内外成人在线| 亚洲免费在线看| 亚洲日本欧美日韩高观看| 香蕉av777xxx色综合一区| 欧美成人综合| 亚洲电影第三页| 美女精品网站| 久久精品久久综合| 国产一区二区日韩精品| 午夜电影亚洲| 亚洲午夜激情网站| 欧美午夜欧美| 亚洲欧美另类国产| 一本色道久久综合亚洲精品不| 欧美国产日韩精品免费观看| 精品成人在线观看| 噜噜噜躁狠狠躁狠狠精品视频| 午夜影院日韩| 国产日韩欧美在线播放不卡| 欧美一区二区三区免费在线看| 一本久久a久久免费精品不卡| 欧美精品亚洲精品| 日韩一区二区高清| 亚洲日本一区二区三区| 欧美成人免费观看| 日韩视频在线免费| 欧美大片一区二区三区| 久久亚洲精品中文字幕冲田杏梨| 伊人成综合网伊人222| 久久综合色天天久久综合图片| 久久精品九九| 亚洲精品色婷婷福利天堂| 亚洲高清一区二区三区| 牛人盗摄一区二区三区视频| 亚洲欧洲日产国产网站| 亚洲第一精品在线| 欧美激情第4页| 一本久道久久综合狠狠爱| 99精品视频网| 国产综合视频| 亚洲第一二三四五区| 欧美日韩精品不卡| 午夜视频精品| 久久精品中文字幕一区二区三区| 亚洲成色最大综合在线| 美女爽到呻吟久久久久| 欧美日韩国产一区二区| 亚洲丝袜av一区| 欧美一区国产二区| 亚洲精华国产欧美| 一区二区三区精品| 国产日韩亚洲欧美| 欧美激情久久久久久| 欧美三级午夜理伦三级中视频| 欧美一区1区三区3区公司| 久久免费精品日本久久中文字幕| 亚洲国产一区二区三区a毛片| 亚洲午夜成aⅴ人片| 亚洲欧美激情一区二区| 亚洲激情电影中文字幕| 国产精品99久久久久久人| 国产亚洲欧美一区二区| 最新日韩av| 国内精品久久久久久| 91久久久亚洲精品| 国产专区欧美精品| 亚洲精品乱码久久久久久日本蜜臀 | 欧美一区二区三区久久精品茉莉花| 国产日韩欧美精品一区| 老鸭窝毛片一区二区三区| 欧美日韩另类视频| 久久久久久9| 欧美精品入口| 久久国产一二区| 欧美日韩高清在线播放| 可以免费看不卡的av网站| 欧美日本网站| 亚洲第一精品久久忘忧草社区| 国产精品久久久久久久久果冻传媒| 久久av一区二区三区亚洲| 欧美日韩精品一区二区| 欧美成人高清视频| 国产综合欧美| 欧美一区二视频在线免费观看| 亚洲欧美视频| 欧美日韩亚洲网| 亚洲裸体在线观看| 日韩一级不卡| 欧美成人一区二区三区片免费| 免费不卡欧美自拍视频| 国产一区欧美日韩| 亚洲欧美日韩精品久久奇米色影视| 99天天综合性| 欧美jizzhd精品欧美巨大免费| 久久这里有精品视频| 国产真实久久| 久久精品一区二区三区不卡牛牛 | 久久亚洲不卡| 理论片一区二区在线| 国产一区二区精品久久91| 亚洲一区二区三区色| 香蕉精品999视频一区二区| 国产精品日韩欧美综合| 亚洲一区二区三区中文字幕| 亚洲已满18点击进入久久 | 亚洲国产经典视频| 免费在线看一区| 亚洲日本无吗高清不卡| 99xxxx成人网| 欧美欧美天天天天操| 亚洲精品网址在线观看| 一本一本久久a久久精品牛牛影视| 欧美激情亚洲一区| 中文亚洲免费| 国产精品一区二区在线观看网站| 午夜在线a亚洲v天堂网2018| 狂野欧美激情性xxxx| 在线观看欧美日本| 亚洲欧洲av一区二区| 女生裸体视频一区二区三区| 亚洲黄色性网站| 欧美日韩午夜激情| 亚洲小视频在线观看| 久久国产福利| 亚洲国产一区在线观看| 欧美日本亚洲| 亚洲欧美日韩一区二区三区在线观看| 久久精品国产亚洲高清剧情介绍| 在线看视频不卡| 欧美日产国产成人免费图片| 亚洲综合欧美| 免费不卡视频| 亚洲一区二区毛片| 国产一区在线免费观看| 欧美风情在线观看| 亚洲一区二三| 欧美成人中文字幕| 性欧美xxxx视频在线观看| 亚洲高清视频中文字幕| 欧美日韩日本国产亚洲在线| 新狼窝色av性久久久久久| 亚洲精品美女在线| 免费观看欧美在线视频的网站| 亚洲香蕉伊综合在人在线视看| 在线精品国精品国产尤物884a| 国产精品成人aaaaa网站| 久久蜜桃香蕉精品一区二区三区| 一区二区毛片| 亚洲国产视频直播| 久久国产精品高清| 亚洲特级片在线| 91久久在线观看| 一区在线观看视频| 国产婷婷色一区二区三区四区| 欧美精品午夜| 欧美精品在线观看播放| 蜜桃久久av|