📄 list.html
字号:
<HTML><!-- -- Copyright (c) 1996-1999 -- Silicon Graphics Computer Systems, Inc. -- -- Permission to use, copy, modify, distribute and sell this software -- and its documentation for any purpose is hereby granted without fee, -- provided that the above copyright notice appears in all copies and -- that both that copyright notice and this permission notice appear -- in supporting documentation. Silicon Graphics makes no -- representations about the suitability of this software for any -- purpose. It is provided "as is" without express or implied warranty. -- -- Copyright (c) 1994 -- Hewlett-Packard Company -- -- Permission to use, copy, modify, distribute and sell this software -- and its documentation for any purpose is hereby granted without fee, -- provided that the above copyright notice appears in all copies and -- that both that copyright notice and this permission notice appear -- in supporting documentation. Hewlett-Packard Company makes no -- representations about the suitability of this software for any -- purpose. It is provided "as is" without express or implied warranty. -- --><Head><Title>list<T, Alloc></Title><!-- Generated by htmldoc --></HEAD><BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" ALINK="#ff0000"> <IMG SRC="CorpID.gif" ALT="SGI" HEIGHT="43" WIDTH="151"> <!--end header--><BR Clear><H1>list<T, Alloc></H1><Table CellPadding=0 CellSpacing=0 width=100%><TR><TD Align=left><Img src = "containers.gif" Alt="" WIDTH = "194" HEIGHT = "38" ></TD><TD Align=right><Img src = "type.gif" Alt="" WIDTH = "194" HEIGHT = "39" ></TD></TR><TR><TD Align=left VAlign=top><b>Category</b>: containers</TD><TD Align=right VAlign=top><b>Component type</b>: type</TD></TR></Table><h3>Description</h3>A <tt>list</tt> is a doubly linked list. That is, it is a<A href="Sequence.html">Sequence</A> that supports both forward andbackward traversal, and (amortized) constant time insertion andremoval of elements at the beginning or the end, or in the middle.<tt>List</tt>s have the important property that insertion and splicingdo not invalidate iterators to list elements, and that even removalinvalidates only the iterators that point to the elements that areremoved. The ordering of iterators may be changed (that is,<tt>list<T>::iterator</tt> might have a different predecessor orsuccessor after a list operation than it did before), but theiterators themselves will not be invalidated or made to point todifferent elements unless that invalidation or mutation isexplicit. <A href="#1">[1]</A><P>Note that singly linked lists, which only support forward traversal,are also sometimes useful. If you do not need backward traversal,then <tt><A href="Slist.html">slist</A></tt> may be more efficientthan <tt>list</tt>.<h3>Definition</h3>Defined in the standard header <A href="list">list</A>, and in the nonstandardbackward-compatibility header <A href="list.h">list.h</A>.<h3>Example</h3><pre>list<int> L;L.push_back(0);L.push_front(1);L.insert(++L.begin(), 2);<A href="copy.html">copy</A>(L.begin(), L.end(), <A href="ostream_iterator.html">ostream_iterator</A><int>(cout, " "));// The values that are printed are 1 2 0</pre><h3>Template parameters</h3><Table border><TR><TH>Parameter</TH><TH>Description</TH><TH>Default</TH></TR><TR><TD VAlign=top><tt>T</tt></TD><TD VAlign=top>The <tt>list</tt>'s value type: the type of object that is stored in the list.</TD><TD VAlign=top> </TD></TR><TR><TD VAlign=top><tt>Alloc</tt></TD><TD VAlign=top>The <tt>list</tt>'s allocator, used for all internal memory management.</TD><TD VAlign=top><tt><A href="Allocators.html">alloc</A></tt></TD></tr></table><h3>Model of</h3><A href="ReversibleContainer.html">Reversible Container</A>, <A href="FrontInsertionSequence.html">Front Insertion Sequence</A>, <A href="BackInsertionSequence.html">Back Insertion Sequence</A>.<h3>Type requirements</h3>None, except for those imposed by the requirements of <A href="ReversibleContainer.html">Reversible Container</A>, <A href="FrontInsertionSequence.html">Front Insertion Sequence</A>, and<A href="BackInsertionSequence.html">Back Insertion Sequence</A>.<h3>Public base classes</h3>None.<h3>Members</h3><Table border><TR><TH>Member</TH><TH>Where defined</TH><TH>Description</TH></TR><TR><TD VAlign=top><tt>value_type</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>The type of object, <tt>T</tt>, stored in the list.</TD></TR><TR><TD VAlign=top><tt>pointer</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Pointer to <tt>T</tt>.</TD></TR><TR><TD VAlign=top><tt>reference</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Reference to <tt>T</tt></TD></TR><TR><TD VAlign=top><tt>const_reference</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Const reference to <tt>T</tt></TD></TR><TR><TD VAlign=top><tt>size_type</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>An unsigned integral type.</TD></TR><TR><TD VAlign=top><tt>difference_type</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>A signed integral type.</TD></TR><TR><TD VAlign=top><tt>iterator</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Iterator used to iterate through a <tt>list</tt>.</TD></TR><TR><TD VAlign=top><tt>const_iterator</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Const iterator used to iterate through a <tt>list</tt>.</TD></TR><TR><TD VAlign=top><tt>reverse_iterator</tt></TD><TD VAlign=top> <A href="ReversibleContainer.html">Reversible Container</A></TD><TD VAlign=top>Iterator used to iterate backwards through a <tt>list</tt>.</TD></TR><TR><TD VAlign=top><tt>const_reverse_iterator</tt></TD><TD VAlign=top> <A href="ReversibleContainer.html">Reversible Container</A></TD><TD VAlign=top>Const iterator used to iterate backwards through a <tt>list</tt>.</TD></TR><TR><TD VAlign=top><tt>iterator begin()</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Returns an <tt>iterator</tt> pointing to the beginning of the <tt>list</tt>.</TD></TR><TR><TD VAlign=top><tt>iterator end()</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Returns an <tt>iterator</tt> pointing to the end of the <tt>list</tt>.</TD></TR><TR><TD VAlign=top><tt>const_iterator begin() const</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Returns a <tt>const_iterator</tt> pointing to the beginning of the <tt>list</tt>.</TD></TR><TR><TD VAlign=top><tt>const_iterator end() const</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Returns a <tt>const_iterator</tt> pointing to the end of the <tt>list</tt>.</TD></TR><TR><TD VAlign=top><tt>reverse_iterator rbegin()</tt></TD><TD VAlign=top> <A href="ReversibleContainer.html">Reversible Container</A></TD><TD VAlign=top>Returns a <tt>reverse_iterator</tt> pointing to the beginning of the reversed list.</TD></TR><TR><TD VAlign=top><tt>reverse_iterator rend()</tt></TD><TD VAlign=top> <A href="ReversibleContainer.html">Reversible Container</A></TD><TD VAlign=top>Returns a <tt>reverse_iterator</tt> pointing to the end of the reversed list.</TD></TR><TR><TD VAlign=top><tt>const_reverse_iterator rbegin() const</tt></TD><TD VAlign=top> <A href="ReversibleContainer.html">Reversible Container</A></TD><TD VAlign=top>Returns a <tt>const_reverse_iterator</tt> pointing to the beginning of the reversed list.</TD></TR><TR><TD VAlign=top><tt>const_reverse_iterator rend() const</tt></TD><TD VAlign=top> <A href="ReversibleContainer.html">Reversible Container</A></TD><TD VAlign=top>Returns a <tt>const_reverse_iterator</tt> pointing to the end of the reversed list.</TD></TR><TR><TD VAlign=top><tt>size_type size() const</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Returns the size of the <tt>list</tt>. Note: you should not assume that this function is constant time. It is permitted to be <i>O(N</i>), where <i>N</i> is the number of elements in the <tt>list</tt>. If you wish to test whether a <tt>list</tt> is empty, you should write <tt>L.empty()</tt> rather than <tt>L.size() == 0</tt>.</TD></TR><TR><TD VAlign=top><tt>size_type max_size() const</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Returns the largest possible size of the <tt>list</tt>.</TD></TR><TR><TD VAlign=top><tt>bool empty() const</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top><tt>true</tt> if the <tt>list</tt>'s size is <tt>0</tt>.</TD></TR><TR><TD VAlign=top><tt>list()</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Creates an empty list.</TD></TR><TR><TD VAlign=top><tt>list(size_type n)</tt></TD><TD VAlign=top> <A href="Sequence.html">Sequence</A></TD><TD VAlign=top>Creates a list with <tt>n</tt> elements, each of which is a copy of <tt>T()</tt>.</TD></TR><TR><TD VAlign=top><tt>list(size_type n, const T& t)</tt></TD><TD VAlign=top> <A href="Sequence.html">Sequence</A></TD><TD VAlign=top>Creates a list with <tt>n</tt> copies of <tt>t</tt>.</TD></TR><TR><TD VAlign=top><tt>list(const list&)</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>The copy constructor.</TD></TR><TR><TD VAlign=top><pre>template <class <A href="InputIterator.html">InputIterator</A>>list(InputIterator f, InputIterator l)<A href="#2">[2]</A></pre></TD><TD VAlign=top> <A href="Sequence.html">Sequence</A></TD><TD VAlign=top>Creates a list with a copy of a range.</TD></TR><TR><TD VAlign=top><tt>~list()</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>The destructor.</TD></TR><TR><TD VAlign=top><tt>list& operator=(const list&)</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>The assignment operator</TD></TR><TR><TD VAlign=top><tt>reference front()</tt></TD><TD VAlign=top> <A href="FrontInsertionSequence.html">Front Insertion Sequence</A></TD><TD VAlign=top>Returns the first element.</TD></TR><TR><TD VAlign=top><tt>const_reference front() const</tt></TD><TD VAlign=top> <A href="FrontInsertionSequence.html">Front Insertion Sequence</A></TD><TD VAlign=top>Returns the first element.</TD></TR><TR><TD VAlign=top><tt>reference back()</tt></TD><TD VAlign=top> <A href="Sequence.html">Sequence</A></TD><TD VAlign=top>Returns the last element.</TD></TR><TR><TD VAlign=top><tt>const_reference back() const</tt></TD><TD VAlign=top> <A href="BackInsertionSequence.html">Back Insertion Sequence</A></TD><TD VAlign=top>Returns the last element.</TD></TR><TR><TD VAlign=top><tt>void push_front(const T&)</tt></TD><TD VAlign=top> <A href="FrontInsertionSequence.html">Front Insertion Sequence</A></TD><TD VAlign=top>Inserts a new element at the beginning.</TD></TR><TR><TD VAlign=top><tt>void push_back(const T&)</tt></TD><TD VAlign=top> <A href="BackInsertionSequence.html">Back Insertion Sequence</A></TD><TD VAlign=top>Inserts a new element at the end.</TD></TR><TR><TD VAlign=top>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -