📄 list.htm
字号:
<pre>
<a name="pushback">Method push_back</a>
Access Public
Classification Modifier
Syntax void push_back(const T& x)
Parameters X is the object to add to the list.
Return None
</pre>
<h3>Description</h3>
<p>
The push_back() method inserts the object X at the rear of the list.
</p>
<hr>
<pre>
<a name="pushfront">Method push_front</a>
Access Public
Classification Modifier
Syntax void push_front(const T& X)
Parameters X is the object to add to the front of the list.
Return None
</pre>
<h3>Description</h3>
<p>
The push_front() method inserts the object X at the front/head of the list.
</p>
<hr>
<pre>
<a name="remove">Method remove</a>
Access Public
Classification Modifier
Syntax void remove(const T& Value)
Parameters Objects that are equivalent to Value are removed from
the list.
Return None
</pre>
<h3>Description</h3>
<p>
The remove() method removes all objects from the list that are equal to Value.
</p>
<hr>
<pre>
<a name="removeif">Method remove_if</a>
Access Public
Classification Modifier
Syntax template <class Predicate> void remove_if(Predicate pred)
Parameters pred is a predicate that will evaluate to either true or false for
each object in the container.
Return None
</pre>
<h3>Description</h3>
<p>
The remove_if() method removes all objects from the list where pred evaluates to
true for that object.
</p>
<hr>
<pre>
<a name="resize">Method resize</a>
Access Public
Classification Modifier
Syntax void resize(size_type sz, T C = T)
Parameters sz is the new size the list will be set to. T is the object
to initalize any new elements to (if any).
Return None
</pre>
<h3>Description</h3>
<p>
The resize() method makes size() == sz. If size() and sz are equal resize() does nothing.
If sz < size() then the appropriate number of objects are removed from the end of the list.
If sz > size() then the list is expanded and the new elements are assigned the value of
T.
</p>
<hr>
<pre>
<a name="reverse">Method reverse</a>
Access Public
Classification Modifier
Syntax void reverse()
Parameters None
Return None
</pre>
<h3>Description</h3>
<p>
The reverse() method reverses the order of the elements in the list.
</p>
<hr>
<pre>
<a name="sort1">Method sort</a>
Access Public
Classification Modifier
Syntax void sort()
Parameters None
Return None
</pre>
<h3>Description</h3>
<p>
This sort() method sorts the objects in the list according the operator < defined for the object.
</p>
<hr>
<pre>
<a name="sort2">Method sort</a>
Access Public
Classification Modifier
Syntax template <class Compare> void sort(Compare comp)
Parameters comp is the comparison object that will be used to sort
the elements in the list. The ordering will be based on
the definition of the () operator for the comp object.
Return None
</pre>
<h3>Description</h3>
<p>
This sort() method sorts the objects in the list according the comp function object.
</p>
<hr>
<pre>
<a name="swap">Method swap</a>
Access Public
Classification Modifier
Syntax void swap(list<T,Allocator>&X)
Parameters X is the list to be swapped.
Return None
</pre>
<h3>Description</h3>
<p>
The swap() method swaps the contents of the current list with the contents of list X.
</p>
<hr>
<pre>
<a name="splice1">Method splice</a>
Access Public
Classification Modifier
Syntax void splice(iterator Pos, list<T,Allocator>& X)
Parameters X is the list to be inserted into the current list.
Return None
</pre>
<h3>Description</h3>
<p>
This splice() method inserts all the elements from list X before position Pos in the current
list. Those elements are then deleted from list X.
</p>
<hr>
<pre>
<a name="splice2">Method splice</a>
Access Public
Classification Modifier
Syntax void splice(iterator Pos, list<T,Allocator>& X, iterator I)
Parameters The element pointed to by I in list X will be inserted into the
current list.
Return None
</pre>
<h3>Description</h3>
<p>
This splice() method inserts the element pointed to by I from list X before position Pos in the current
list. That element is then deleted from list X.
</p>
<hr>
<pre>
<a name="splice3">Method splice</a>
Access Public
Classification Modifier
Syntax void splice(iterator Pos, list<T,Allocator>& X, iterator First, iterator Last)
Parameters The elements in the range [First,Last)in list X will be inserted into the
current list before position Pos.
Return None
</pre>
<h3>Description</h3>
<p>
This splice() method inserts the elements in the range [First,Last)from list X before position Pos in the current
list. Those elements are then deleted from list X.
</p>
<hr>
<pre>
<a name="unique1">Method unique</a>
Access Public
Classification Modifier
Syntax void unique()
Parameters None
Return None
</pre>
<h3>Description</h3>
<p>
This unique() method erases all duplicate elements from the list and leaves only the first object
of each value in the list.
</p>
<hr>
<a name="unique2">Method unique</a>
Access Public
Classification Modifier
Syntax template <class BinaryPredicate> void unique(BinaryPredicate binary_pred)
Parameters binary_pred is predicate that evaluates true or false for every pair of objects
in the list.
Return None
</pre>
<h3>Description</h3>
<p>
This unique() method erases all duplicate elements from the list where binary_pred evaluates to
true. and leaves only the first object of each value in the list.
</p>
<hr>
<a name="example"></a>
<img src="lego.gif">
<pre>
6 #include <list>
7 #include <iostream>
8
9 using namespace std;
10
11 void main(void)
12 {
13 list<double> MyList;
14 int N = 0;
15 while(N < 6)
16 {
17 MyList.push_back(N + 3.14);
18 N++;
19 }
20 list<double>::iterator M = MyList.begin();
21 while(N)
22 {
23 cout << "MyList : " << *M << endl;
24 M++;
25 N--;
26 }
27 N = MyList.size();
28 M = MyList.end();
29 M--;
30 cout << " Reverse Direction-----------" << endl;
31 while(N)
32 {
33 cout << "MyList : " << *M << endl;
34 M--;
35 N--;
36 }
37 }
</pre>
<hr>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -