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

📄 set_1735.htm

📁 ARM编辑、编译软件
💻 HTM
字号:
<HTML><TITLE>set_symmetric_difference </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>set_symmetric_difference </H2>
<HR><PRE>     Algorithm</PRE><HR>
<A NAME="Summary"><H3>Summary</H3></A>
<P>Basic set operation for sorted sequences.</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="#Warning"><LI>Warning</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 InputIterator1, class InputIterator2,
          class OutputIterator>
OutputIterator
<B>set_symmetric_difference </B>(InputIterator1 first1,
                          InputIterator1 last1,
                          InputIterator2 first2,
                          InputIterator2 last2,
                          OutputIterator result);
template &#60;class InputIterator1, class InputIterator2,
          class OutputIterator, class Compare>
OutputIterator
<B>set_symmetric_difference </B>(InputIterator1 first1,
                          InputIterator1 last1,
                          InputIterator2 first2,
                          InputIterator2 last2,
                          OutputIterator result, Compare comp);
</PRE>
<A NAME="Description"><H3>Description</H3></A>
<P><B><I>set_symmetric_difference</B></I> constructs a sorted symmetric difference of the elements from the two ranges.  This means that the constructed range includes copies of the elements that are present in the range <SAMP>[first1, last1)</SAMP> but not present in the range <SAMP>[first2, last2)</SAMP><I>and</I> copies of the elements that are present in the range <SAMP>[first2, last2)</SAMP> but not in the range <SAMP>[first1, last1)</SAMP>.  It returns the end of the constructed range.  </P>
<P>For example, suppose we have two sets:</P>
<PRE>1 2 3 4 5</PRE>
<PRE></PRE><P>and</P>
<PRE>3 4 5 6 7</PRE>
<PRE></PRE><P>The <B><I>set_symmetric_difference</B></I> of these two sets is:</P>
<PRE>1 2 6 7</PRE>
<PRE></PRE><P>The result of <B><I>set_symmetric_difference</B></I> is undefined if the result range overlaps with either of the original ranges. </P>
<P><B><I>set_symmetric_difference</B></I> assumes that the ranges are sorted using the default comparision operator less than (<SAMP>&#60;</SAMP>), unless an alternative comparison operator (<SAMP>comp</SAMP>) is provided. </P>
<P>Use the <B><I>set_symmetric_difference</B></I> algorithm to return a result that includes elements that are present in the first set and not in the second.</P>
<A NAME="Complexity"><H3>Complexity</H3></A>
<P>At most <SAMP>((last1 - first1) + (last2 - first2)) * 2 -1</SAMP>  comparisons are performed.</P>
<A NAME="Example"><H3>Example</H3></A>
<PRE>//
// set_s_di.cpp
//
 #include&#60;algorithm>
 #include&#60;set>
 #include &#60;istream.h>
 int main()
 {
   //Initialize some sets
   int a1[] = {1,3,5,7,9,11};
   int a3[] = {3,5,7,8};
   set&#60;int, less&#60;int> > odd(a1,a1+6), result, 
                        small(a3,a3+4);
   //Create an insert_iterator for result
   insert_iterator&#60;set&#60;int, less&#60;int> > > 
                 res_ins(result, result.begin());
   //Demonstrate set_symmetric_difference
   cout &#60;&#60; "The symmetric difference of:" &#60;&#60; endl &#60;&#60; "{";
   copy(small.begin(),small.end(),
        ostream_iterator&#60;int>(cout," "));
   cout &#60;&#60; "} with {";
   copy(odd.begin(),odd.end(),
        ostream_iterator&#60;int>(cout," "));
   cout &#60;&#60; "} =" &#60;&#60; endl &#60;&#60; "{";
   <B>set_symmetric_difference</B>(small.begin(), small.end(),
                       odd.begin(), odd.end(), res_ins);
   copy(result.begin(),result.end(),
        ostream_iterator&#60;int>(cout," "));
   cout &#60;&#60; "}" &#60;&#60; endl &#60;&#60; endl;
   return 0;
 }
Output :
The symmetric difference of:
{3 5 7 8 } with {1 3 5 7 9 11 } =
{1 8 9 11 }</PRE>
<A NAME="Warning"><H3>Warning</H3></A>
<P>If your compiler does not support default template parameters, then you need to always supply the <SAMP>Compare</SAMP> template argument and the <SAMP>Allocator</SAMP> template argument. For instance, you will need to write :</P>
<P><SAMP>set&#60;int, less&#60;int>, allocator></SAMP></P>
<P>instead of :</P>
<P><SAMP>set&#60;int></SAMP></P>
<A NAME="See Also"><H3>See Also</H3></A>
<P><A HREF="inc_3676.htm"><B><I>includes</B></I></A>, <A HREF="set_1649.htm"><B><I>set,</B></I></A> <A HREF="set_6462.htm"><B><I>set_union</B></I></A>,<A HREF="set_9182.htm"><B><I> set_intersection</B></I></A>, <A HREF="set_0972.htm"><B><I>set_difference</B></I></A></P>
<HR>
<A HREF="set_9182.htm"><IMG SRC="images/prev.gif"></A> <A HREF="ref.htm#contents"><IMG SRC="images/toc.gif"></A> <A HREF="set_6462.htm"><IMG SRC="images/next.gif"></A></BODY></HTML>

⌨️ 快捷键说明

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