⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fin_7707.htm

📁 ARM编辑、编译软件
💻 HTM
字号:
<HTML><TITLE>find_end</TITLE><BODY>
<A HREF="ref.htm"><IMG SRC="images/banner.gif"></A>
<P><STRONG>Click on the banner to return to the Class Reference home page.</STRONG></P>
<P>&copy;Copyright 1996 Rogue Wave Software</P>
<H2>find_end</H2>
<HR><PRE><B><I>     </I></B>Algorithm</B></I>
</PRE><HR>
<A NAME="Summary"><H3>Summary</H3></A>
<P>Finds a subsequence of equal values in a sequence.</P>
<H3>Contents</H3>
<UL>
<A HREF="#Synopsis"><LI>Synopsis</LI></A>
<A HREF="#Description"><LI>Description</LI></A>
<A HREF="#Complexity"><LI>Complexity</LI></A>
<A HREF="#Example"><LI>Example</LI></A>
<A HREF="#Warnings"><LI>Warnings</LI></A>
<A HREF="#See Also"><LI>See Also</LI></A>
</UL>
<A NAME="Synopsis"><H3>Synopsis</H3></A>
<PRE>#include &#60;algorithm></PRE>
<PRE>
template &#60;class ForwardIterator1, class ForwardIterator2></PRE>
<PRE>ForwardIterator1 <B>find_end</B>(ForwardIterator1 first1,
                          ForwardIterator1 last1,
                          ForwardIterator2 first2, 
                          ForwardIterator2 last2);
template &#60;class Forward Iterator1, class ForwardIterator2, 
          class BinaryPredicate>
  ForwardIterator1 <B>find_end</B>(ForwardIterator1 first1,  
                            ForwardIterator1 last1,
                            ForwardIterator2 first2,
                            ForwardIterator2 last2,
                            BinaryPredicate pred);
</PRE>
<A NAME="Description"><H3>Description</H3></A>
<P>The<B><I> find_end </B></I>algorithm finds the last occurrence of a subsequence, indicated by <SAMP>[first2, last2)</SAMP>, in a sequence, <SAMP>[first1,last1)</SAMP>.  The algorithm returns an iterator pointing to the first element of the found subsequence, or <SAMP>last1</SAMP> if no match is found.</P>
<P>More precisely, the<B><I> find_end </B></I>algorithm returns the  last  iterator  <SAMP>i</SAMP> in the range <SAMP>[first1, last1 - (last2-first2))</SAMP>  such that for any non-negative integer <SAMP>n &#60; (last2-first2)</SAMP>, the  following   corresponding   conditions  hold:  </P>
<PRE>*(i+n)  ==  *(first2+n),    </PRE>
<PRE>pred(*(i+n),*(first2+n)) == true.  
</PRE><P>Or returns <SAMP>last1</SAMP> if no such iterator is found.</P>
<P>Two versions of the algorithm exist.  The first uses the equality operator as the default binary predicate, and the second allows you to specify a binary predicate.</P>
<A NAME="Complexity"><H3>Complexity</H3></A>
<P>At most <SAMP>(last2-first2)*(last1-first1-(last2-first2)+1)</SAMP> applications of the corresponding predicate are done.</P>
<A NAME="Example"><H3>Example</H3></A>
<PRE>//
// find_end.cpp
//
#include&#60;vector>
#include&#60;iterator>
#include&#60;algorithm>
#include&#60;iostream.h>
int main()
{
   typedef vector&#60;int>::iterator iterator;
   int d1[10] = {0,1,6,5,3,2,2,6,5,7};
   int d2[4] = {6,5,0,0}</PRE>
<PRE>   //
   // Set up two vectors.
   //
   vector&#60;int> v1(d1+0, d1+10), v2(d2+0, d2+2);
   //
   // Try both find_first_of variants.
   //
   iterator it1 = find_first_of (v1.begin(), v1.end(), v2.begin(), 
                                 v2.end());</PRE>
<PRE>   iterator it2 = find_first_of (v1.begin(), v1.end(), v2.begin(), 
                                 v2.end(), equal_to&#60;int>());
   //
   // Try both find_end variants.
   //
   iterator it3 = <B>find_end</B> (v1.begin(), v1.end(), v2.begin(), 
                            v2.end());</PRE>
<PRE>   iterator it4 = <B>find_end</B> (v1.begin(), v1.end(), v2.begin(),
                            v2.end(), equal_to&#60;int>());
   //
   // Output results of find_first_of.
   // Iterator now points to the first element that matches one of   
   // a set of values
   //
   cout &#60;&#60; "For the vectors: ";
   copy (v1.begin(), v1.end(), ostream_iterator&#60;int>(cout," "));
   cout &#60;&#60; " and ";
   copy (v2.begin(), v2.end(), ostream_iterator&#60;int>(cout," "));
   cout&#60;&#60; endl ,, endl
       &#60;&#60; "both versions of find_first_of point to: "
       &#60;&#60; *it1 &#60;&#60; endl &#60;&#60; "with first_of address = " &#60;&#60; it1   
       &#60;&#60; endl ;
   //
   //Output results of find_end.
   // Iterator now points to the first element of the last find 
   //subsequence.
   //
   cout &#60;&#60; endl &#60;&#60; endl
        &#60;&#60; "both versions of find_end point to: "
        &#60;&#60; *it3 &#60;&#60; endl &#60;&#60; "with find_end address = " &#60;&#60; it3 
        &#60;&#60; endl ;
   return 0;
}
Output :
For the vectors: 0 1 6 5 3 2 2 6 5 7  and 6 5
both versions of find_first_of point to: 6
with first_of address = 0x100005c0
both versions of find_end point to: 6
with find_end address = 0x100005d4</PRE>
<A NAME="Warnings"><H3>Warnings</H3></A>
<P>If your compiler does not support default template parameters then you need to always supply the <SAMP>Allocator</SAMP> template argument.  For instance you'll have to write:</P>
<PRE>vector&#60;int, allocator></PRE>
<PRE></PRE><P>instead of:</P>
<PRE>vector&#60;int></PRE>
<A NAME="See Also"><H3>See Also</H3></A>
<P><A HREF="Alg_5157.htm"><B><I>Algorithms</B></I></A>, <A HREF="fin_7988.htm"><B><I>find</B></I></A>, <A HREF="fin_2105.htm"><B><I>find_if</B></I></A>, <A HREF="adj_8817.htm"><B><I>adjacent_find</B></I></A></P>
<HR>
<A HREF="fin_7988.htm"><IMG SRC="images/prev.gif"></A> <A HREF="ref.htm#contents"><IMG SRC="images/toc.gif"></A> <A HREF="fin_8583.htm"><IMG SRC="images/next.gif"></A></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -