A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B_Tutorial%2FDevelopment%2FSort</id>
		<title>C++ Tutorial/Development/Sort - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B_Tutorial%2FDevelopment%2FSort"/>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B_Tutorial/Development/Sort&amp;action=history"/>
		<updated>2026-04-10T18:51:28Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B_Tutorial/Development/Sort&amp;diff=2155&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B_Tutorial/Development/Sort&amp;diff=2155&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:17Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://cppe.ru/index.php?title=C%2B%2B_Tutorial/Development/Sort&amp;diff=2156&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://cppe.ru/index.php?title=C%2B%2B_Tutorial/Development/Sort&amp;diff=2156&amp;oldid=prev"/>
				<updated>2010-05-25T10:29:01Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==A Bubble sort==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt; &lt;br /&gt;
#include &amp;lt;cstdlib&amp;gt; &lt;br /&gt;
using namespace std; &lt;br /&gt;
 &lt;br /&gt;
int main() &lt;br /&gt;
{ &lt;br /&gt;
  int nums[10]; &lt;br /&gt;
  int a, b, t; &lt;br /&gt;
  int size; &lt;br /&gt;
 &lt;br /&gt;
  size = 10; // number of elements to sort &lt;br /&gt;
 &lt;br /&gt;
  for(t=0; t&amp;lt;size; t++) &lt;br /&gt;
      nums[t] = rand(); &lt;br /&gt;
 &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Original array is:\n   &amp;quot;; &lt;br /&gt;
  for(t=0; t&amp;lt;size; t++) &lt;br /&gt;
      cout &amp;lt;&amp;lt; nums[t] &amp;lt;&amp;lt; &amp;quot; &amp;quot;; &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;; &lt;br /&gt;
 &lt;br /&gt;
  // This is the bubble sort. &lt;br /&gt;
  for(a=1; a&amp;lt;size; a++) &lt;br /&gt;
    for(b=size-1; b&amp;gt;=a; b--) { &lt;br /&gt;
      if(nums[b-1] &amp;gt; nums[b]) { // if out of order &lt;br /&gt;
        // exchange elements  &lt;br /&gt;
        t = nums[b-1]; &lt;br /&gt;
        nums[b-1] = nums[b]; &lt;br /&gt;
        nums[b] = t; &lt;br /&gt;
      } &lt;br /&gt;
    } &lt;br /&gt;
 &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;\nSorted array is:\n   &amp;quot;; &lt;br /&gt;
  for(t=0; t&amp;lt;size; t++) &lt;br /&gt;
      cout &amp;lt;&amp;lt; nums[t] &amp;lt;&amp;lt; &amp;quot; &amp;quot;; &lt;br /&gt;
 &lt;br /&gt;
  return 0; &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Original array is:&lt;br /&gt;
   41 18467 6334 26500 19169 15724 11478 29358 26962 24464&lt;br /&gt;
Sorted array is:&lt;br /&gt;
   41 6334 11478 15724 18467 19169 24464 26500 26962 29358&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A recursive version of Quicksort for sorting characters==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt; &lt;br /&gt;
#include &amp;lt;cstring&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
using namespace std; &lt;br /&gt;
 &lt;br /&gt;
void quicksort(char *items, int len); &lt;br /&gt;
 &lt;br /&gt;
void qs(char *items, int left, int right); &lt;br /&gt;
 &lt;br /&gt;
int main() { &lt;br /&gt;
 &lt;br /&gt;
  char str[] = &amp;quot;fdsawertgsvbnhgfdertygfd&amp;quot;; &lt;br /&gt;
 &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Original order: &amp;quot; &amp;lt;&amp;lt; str &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;; &lt;br /&gt;
 &lt;br /&gt;
  quicksort(str, strlen(str)); &lt;br /&gt;
 &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Sorted order: &amp;quot; &amp;lt;&amp;lt; str &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;; &lt;br /&gt;
 &lt;br /&gt;
  return 0; &lt;br /&gt;
 &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
void quicksort(char *items, int len) &lt;br /&gt;
{ &lt;br /&gt;
  qs(items, 0, len-1); &lt;br /&gt;
} &lt;br /&gt;
 &lt;br /&gt;
void qs(char *items, int left, int right)  &lt;br /&gt;
{  &lt;br /&gt;
  int i, j;  &lt;br /&gt;
  char x, y;  &lt;br /&gt;
  &lt;br /&gt;
  i = left; j = right;  &lt;br /&gt;
  x = items[( left+right) / 2 ];  &lt;br /&gt;
  &lt;br /&gt;
  do {  &lt;br /&gt;
    while((items[i] &amp;lt; x) &amp;amp;&amp;amp; (i &amp;lt; right)) &lt;br /&gt;
       i++;  &lt;br /&gt;
    while((x &amp;lt; items[j]) &amp;amp;&amp;amp; (j &amp;gt; left)) &lt;br /&gt;
       j--;  &lt;br /&gt;
  &lt;br /&gt;
    if(i &amp;lt;= j) {  &lt;br /&gt;
      y = items[i];  &lt;br /&gt;
      items[i] = items[j];  &lt;br /&gt;
      items[j] = y;  &lt;br /&gt;
      i++; j--;  &lt;br /&gt;
    }  &lt;br /&gt;
  } while(i &amp;lt;= j);  &lt;br /&gt;
  &lt;br /&gt;
  if(left &amp;lt; j) &lt;br /&gt;
     qs(items, left, j);  &lt;br /&gt;
  if(i &amp;lt; right) &lt;br /&gt;
     qs(items, i, right);  &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Original order: fdsawertgsvbnhgfdertygfd&lt;br /&gt;
Sorted order: abdddeefffggghnrrssttvwy&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==how to declare your own function and function pointer to be used with qsort( )==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
#define IMAXVALUES 10&lt;br /&gt;
int icompare_funct(const void *iresult_a, const void *iresult_b);&lt;br /&gt;
int (*ifunct_ptr)(const void *,const void *);&lt;br /&gt;
int main( )&lt;br /&gt;
{&lt;br /&gt;
 int i;&lt;br /&gt;
 int iarray[IMAXVALUES]={0,5,3,2,8,7,9,1,4,6};&lt;br /&gt;
 ifunct_ptr=icompare_funct;&lt;br /&gt;
 qsort(iarray,IMAXVALUES,sizeof(int),ifunct_ptr);&lt;br /&gt;
 for(i = 0; i &amp;lt; IMAXVALUES; i++)&lt;br /&gt;
   cout &amp;lt;&amp;lt;&amp;quot;[{||}]&amp;quot; &amp;lt;&amp;lt; iarray[i];&lt;br /&gt;
}&lt;br /&gt;
int icompare_funct(const void *iresult_a, const void *iresult_b)&lt;br /&gt;
{&lt;br /&gt;
 return((*(int *)iresult_a) - (*(int *)iresult_b));&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Quick Sort==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int *swapnumbers(int rawdata[], int lower, int upper);&lt;br /&gt;
int *quicksort(int rawdata[], int first, int last);&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    int unsorted[10],i;&lt;br /&gt;
    int *sorted;&lt;br /&gt;
    unsorted[0] = 9;&lt;br /&gt;
    unsorted[1] = 8;&lt;br /&gt;
    unsorted[2] = 7;&lt;br /&gt;
    unsorted[3] = 7;&lt;br /&gt;
    unsorted[4] = 6;&lt;br /&gt;
    unsorted[5] = 5;&lt;br /&gt;
    unsorted[6] = 5;&lt;br /&gt;
    unsorted[7] = 4;&lt;br /&gt;
    unsorted[8] = 4;&lt;br /&gt;
    unsorted[9] = 2;&lt;br /&gt;
    sorted = quicksort(unsorted, 0, 10);&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;This is your array sorted:&amp;quot;&amp;lt;&amp;lt; endl;&lt;br /&gt;
    for(i = 0; i &amp;lt; 10; i++)&lt;br /&gt;
    {&lt;br /&gt;
        cout &amp;lt;&amp;lt; sorted[i] &amp;lt;&amp;lt; endl;&lt;br /&gt;
    }&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
int *quicksort(int rawdata[], int first, int last)&lt;br /&gt;
{&lt;br /&gt;
    int lower = first+1, upper = last;&lt;br /&gt;
    int bound;&lt;br /&gt;
    rawdata = swapnumbers(rawdata, first, (first+last)/2);&lt;br /&gt;
    bound = rawdata[first];&lt;br /&gt;
    while(lower &amp;lt;= upper)&lt;br /&gt;
    {&lt;br /&gt;
        while(rawdata[lower] &amp;lt; bound)&lt;br /&gt;
            lower++;&lt;br /&gt;
        while(bound &amp;lt; rawdata[upper])&lt;br /&gt;
            upper--;&lt;br /&gt;
        if(lower &amp;lt; upper)&lt;br /&gt;
        {&lt;br /&gt;
            rawdata = swapnumbers(rawdata, lower++, upper--);&lt;br /&gt;
        }&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            lower++;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    rawdata = swapnumbers(rawdata, upper, first);&lt;br /&gt;
    if(first &amp;lt; upper-1)&lt;br /&gt;
    {&lt;br /&gt;
        rawdata = quicksort(rawdata, first, upper-1);&lt;br /&gt;
    }&lt;br /&gt;
    if(upper+1 &amp;lt; last)&lt;br /&gt;
    {&lt;br /&gt;
        rawdata = quicksort(rawdata, upper+1, last);&lt;br /&gt;
    }&lt;br /&gt;
    return(rawdata);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int *swapnumbers(int rawdata[], int lower, int upper)&lt;br /&gt;
{&lt;br /&gt;
    int temp;&lt;br /&gt;
    temp = rawdata[lower];&lt;br /&gt;
    rawdata[lower] = rawdata[upper];&lt;br /&gt;
    rawdata[upper] = temp;&lt;br /&gt;
    return(rawdata);&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;This is your array sorted:&lt;br /&gt;
0&lt;br /&gt;
2&lt;br /&gt;
4&lt;br /&gt;
4&lt;br /&gt;
5&lt;br /&gt;
5&lt;br /&gt;
6&lt;br /&gt;
7&lt;br /&gt;
7&lt;br /&gt;
8&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Selection Sort==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt; &lt;br /&gt;
using std::cout; &lt;br /&gt;
using std::endl; &lt;br /&gt;
#include &amp;lt;iomanip&amp;gt;&lt;br /&gt;
using std::setw;&lt;br /&gt;
void selectionSort( int * const, const int );&lt;br /&gt;
void swap( int * const, int * const );&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   const int arraySize = 10;&lt;br /&gt;
   int a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 9, 1, 5, 7 };&lt;br /&gt;
   selectionSort( a, arraySize );&lt;br /&gt;
   for ( int j = 0; j &amp;lt; arraySize; j++ )&lt;br /&gt;
      cout &amp;lt;&amp;lt; a[ j ];&lt;br /&gt;
   return 0;&lt;br /&gt;
}&lt;br /&gt;
void selectionSort( int * const array, const int size )&lt;br /&gt;
{&lt;br /&gt;
   int smallest;&lt;br /&gt;
   for ( int i = 0; i &amp;lt; size - 1; i++ )&lt;br /&gt;
   {&lt;br /&gt;
      smallest = i;&lt;br /&gt;
      for ( int index = i + 1; index &amp;lt; size; index++ )&lt;br /&gt;
         if ( array[ index ] &amp;lt; array[ smallest ] )&lt;br /&gt;
            smallest = index;&lt;br /&gt;
      swap( &amp;amp;array[ i ], &amp;amp;array[ smallest ] );&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
void swap( int * const element1Ptr, int * const element2Ptr )&lt;br /&gt;
{&lt;br /&gt;
   int hold = *element1Ptr;&lt;br /&gt;
   *element1Ptr = *element2Ptr;&lt;br /&gt;
   *element2Ptr = hold;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;124567891012&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Sort Tracer==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;/* The following code example is taken from the book&lt;br /&gt;
 * &amp;quot;C++ Templates - The Complete Guide&amp;quot;&lt;br /&gt;
 * by David Vandevoorde and Nicolai M. Josuttis, Addison-Wesley, 2002&lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright David Vandevoorde and Nicolai M. Josuttis 2002.&lt;br /&gt;
 * Permission to copy, use, modify, sell and distribute this software&lt;br /&gt;
 * is granted provided this copyright notice appears in all copies.&lt;br /&gt;
 * This software is provided &amp;quot;as is&amp;quot; without express or implied&lt;br /&gt;
 * warranty, and with no claim as to its suitability for any purpose.&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
class SortTracer {&lt;br /&gt;
  private:&lt;br /&gt;
    int value;                // integer value to be sorted&lt;br /&gt;
    int generation;           // generation of this tracer&lt;br /&gt;
    static long n_created;    // number of constructor calls&lt;br /&gt;
    static long n_destroyed;  // number of destructor calls&lt;br /&gt;
    static long n_assigned;   // number of assignments&lt;br /&gt;
    static long n_compared;   // number of comparisons&lt;br /&gt;
    static long n_max_live;   // maximum of existing objects&lt;br /&gt;
    // recompute maximum of existing objects&lt;br /&gt;
    static void update_max_live() {&lt;br /&gt;
        if (n_created-n_destroyed &amp;gt; n_max_live) {&lt;br /&gt;
            n_max_live = n_created-n_destroyed;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
  public:&lt;br /&gt;
    static long creations() {&lt;br /&gt;
        return n_created;&lt;br /&gt;
    }&lt;br /&gt;
    static long destructions() {&lt;br /&gt;
        return n_destroyed;&lt;br /&gt;
    }&lt;br /&gt;
    static long assignments() {&lt;br /&gt;
        return n_assigned;&lt;br /&gt;
    }&lt;br /&gt;
    static long comparisons() {&lt;br /&gt;
        return n_compared;&lt;br /&gt;
    }&lt;br /&gt;
    static long max_live() {&lt;br /&gt;
        return n_max_live;&lt;br /&gt;
    }&lt;br /&gt;
  public:&lt;br /&gt;
    // constructor&lt;br /&gt;
    SortTracer (int v = 0) : value(v), generation(1) {&lt;br /&gt;
        ++n_created;&lt;br /&gt;
        update_max_live();&lt;br /&gt;
        std::cerr &amp;lt;&amp;lt; &amp;quot;SortTracer #&amp;quot; &amp;lt;&amp;lt; n_created&lt;br /&gt;
                  &amp;lt;&amp;lt; &amp;quot;, created generation &amp;quot; &amp;lt;&amp;lt; generation&lt;br /&gt;
                  &amp;lt;&amp;lt; &amp;quot; (total: &amp;quot; &amp;lt;&amp;lt; n_created - n_destroyed&lt;br /&gt;
                  &amp;lt;&amp;lt; &amp;quot;)\n&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    // copy constructor&lt;br /&gt;
    SortTracer (SortTracer const&amp;amp; b)&lt;br /&gt;
     : value(b.value), generation(b.generation+1) {&lt;br /&gt;
        ++n_created;&lt;br /&gt;
        update_max_live();&lt;br /&gt;
        std::cerr &amp;lt;&amp;lt; &amp;quot;SortTracer #&amp;quot; &amp;lt;&amp;lt; n_created&lt;br /&gt;
                  &amp;lt;&amp;lt; &amp;quot;, copied as generation &amp;quot; &amp;lt;&amp;lt; generation&lt;br /&gt;
                  &amp;lt;&amp;lt; &amp;quot; (total: &amp;quot; &amp;lt;&amp;lt; n_created - n_destroyed&lt;br /&gt;
                  &amp;lt;&amp;lt; &amp;quot;)\n&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    // destructor&lt;br /&gt;
    ~SortTracer() {&lt;br /&gt;
        ++n_destroyed;&lt;br /&gt;
        update_max_live();&lt;br /&gt;
        std::cerr &amp;lt;&amp;lt; &amp;quot;SortTracer generation &amp;quot; &amp;lt;&amp;lt; generation&lt;br /&gt;
                  &amp;lt;&amp;lt; &amp;quot; destroyed (total: &amp;quot;&lt;br /&gt;
                  &amp;lt;&amp;lt; n_created - n_destroyed &amp;lt;&amp;lt; &amp;quot;)\n&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    // assignment&lt;br /&gt;
    SortTracer&amp;amp; operator= (SortTracer const&amp;amp; b) {&lt;br /&gt;
        ++n_assigned;&lt;br /&gt;
        std::cerr &amp;lt;&amp;lt; &amp;quot;SortTracer assignment #&amp;quot; &amp;lt;&amp;lt; n_assigned&lt;br /&gt;
                  &amp;lt;&amp;lt; &amp;quot; (generation &amp;quot; &amp;lt;&amp;lt; generation&lt;br /&gt;
                  &amp;lt;&amp;lt; &amp;quot; = &amp;quot; &amp;lt;&amp;lt; b.generation&lt;br /&gt;
                  &amp;lt;&amp;lt; &amp;quot;)\n&amp;quot;;&lt;br /&gt;
        value = b.value;&lt;br /&gt;
        return *this;&lt;br /&gt;
    }&lt;br /&gt;
    // comparison&lt;br /&gt;
    friend bool operator &amp;lt; (SortTracer const&amp;amp; a,&lt;br /&gt;
                            SortTracer const&amp;amp; b) {&lt;br /&gt;
        ++n_compared;&lt;br /&gt;
        std::cerr &amp;lt;&amp;lt; &amp;quot;SortTracer comparison #&amp;quot; &amp;lt;&amp;lt; n_compared&lt;br /&gt;
                  &amp;lt;&amp;lt; &amp;quot; (generation &amp;quot; &amp;lt;&amp;lt; a.generation&lt;br /&gt;
                  &amp;lt;&amp;lt; &amp;quot; &amp;lt; &amp;quot; &amp;lt;&amp;lt; b.generation&lt;br /&gt;
                  &amp;lt;&amp;lt; &amp;quot;)\n&amp;quot;;&lt;br /&gt;
        return a.value &amp;lt; b.value;&lt;br /&gt;
    }&lt;br /&gt;
    int val() const {&lt;br /&gt;
        return value;&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
long SortTracer::n_created = 0;&lt;br /&gt;
long SortTracer::n_destroyed = 0;&lt;br /&gt;
long SortTracer::n_max_live = 0;&lt;br /&gt;
long SortTracer::n_assigned = 0;&lt;br /&gt;
long SortTracer::n_compared = 0;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    // prepare sample input:&lt;br /&gt;
    SortTracer input[] = { 7, 3, 5, 6, 4, 2, 0, 1, 9, 8 };&lt;br /&gt;
    // print initial values:&lt;br /&gt;
    for (int i=0; i&amp;lt;10; ++i) {&lt;br /&gt;
        std::cerr &amp;lt;&amp;lt; input[i].val() &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    std::cerr &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    // remember initial conditions:&lt;br /&gt;
    long created_at_start = SortTracer::creations();&lt;br /&gt;
    long max_live_at_start = SortTracer::max_live();&lt;br /&gt;
    long assigned_at_start = SortTracer::assignments();&lt;br /&gt;
    long compared_at_start = SortTracer::comparisons();&lt;br /&gt;
    // execute algorithm:&lt;br /&gt;
    std::cerr &amp;lt;&amp;lt; &amp;quot;---[ Start std::sort() ]--------------------\n&amp;quot;;&lt;br /&gt;
    std::sort&amp;lt;&amp;gt;(&amp;amp;input[0], &amp;amp;input[9]+1);&lt;br /&gt;
    std::cerr &amp;lt;&amp;lt; &amp;quot;---[ End std::sort() ]----------------------\n&amp;quot;;&lt;br /&gt;
    // verify result:&lt;br /&gt;
    for (int i=0; i&amp;lt;10; ++i) {&lt;br /&gt;
        std::cerr &amp;lt;&amp;lt; input[i].val() &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    std::cerr &amp;lt;&amp;lt; &amp;quot;\n\n&amp;quot;;&lt;br /&gt;
    // final report:&lt;br /&gt;
    std::cerr &amp;lt;&amp;lt; &amp;quot;std::sort() of 10 SortTracer&amp;quot;s&amp;quot;&lt;br /&gt;
              &amp;lt;&amp;lt; &amp;quot; was performed by:\n &amp;quot;&lt;br /&gt;
              &amp;lt;&amp;lt; SortTracer::creations() - created_at_start&lt;br /&gt;
              &amp;lt;&amp;lt; &amp;quot; temporary tracers\n &amp;quot;&lt;br /&gt;
              &amp;lt;&amp;lt; &amp;quot;up to &amp;quot;&lt;br /&gt;
              &amp;lt;&amp;lt; SortTracer::max_live()&lt;br /&gt;
              &amp;lt;&amp;lt; &amp;quot; tracers at the same time (&amp;quot;&lt;br /&gt;
              &amp;lt;&amp;lt; max_live_at_start &amp;lt;&amp;lt; &amp;quot; before)\n &amp;quot;&lt;br /&gt;
              &amp;lt;&amp;lt; SortTracer::assignments() - assigned_at_start&lt;br /&gt;
              &amp;lt;&amp;lt; &amp;quot; assignments\n &amp;quot;&lt;br /&gt;
              &amp;lt;&amp;lt; SortTracer::comparisons() - compared_at_start&lt;br /&gt;
              &amp;lt;&amp;lt; &amp;quot; comparisons\n\n&amp;quot;;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;SortTracer #1, created generation 1 (total: 1)&lt;br /&gt;
SortTracer #2, created generation 1 (total: 2)&lt;br /&gt;
SortTracer #3, created generation 1 (total: 3)&lt;br /&gt;
SortTracer #4, created generation 1 (total: 4)&lt;br /&gt;
SortTracer #5, created generation 1 (total: 5)&lt;br /&gt;
SortTracer #6, created generation 1 (total: 6)&lt;br /&gt;
SortTracer #7, created generation 1 (total: 7)&lt;br /&gt;
SortTracer #8, created generation 1 (total: 8)&lt;br /&gt;
SortTracer #9, created generation 1 (total: 9)&lt;br /&gt;
SortTracer #10, created generation 1 (total: 10)&lt;br /&gt;
7 3 5 6 4 2 0 1 9 8&lt;br /&gt;
---[ Start std::sort() ]--------------------&lt;br /&gt;
SortTracer #11, copied as generation 2 (total: 11)&lt;br /&gt;
SortTracer comparison #1 (generation 2 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #1 (generation 1 = 1)&lt;br /&gt;
SortTracer assignment #2 (generation 1 = 2)&lt;br /&gt;
SortTracer generation 2 destroyed (total: 10)&lt;br /&gt;
SortTracer #12, copied as generation 2 (total: 11)&lt;br /&gt;
SortTracer comparison #2 (generation 2 &amp;lt; 1)&lt;br /&gt;
SortTracer #13, copied as generation 3 (total: 12)&lt;br /&gt;
SortTracer comparison #3 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #3 (generation 1 = 1)&lt;br /&gt;
SortTracer comparison #4 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #4 (generation 1 = 3)&lt;br /&gt;
SortTracer generation 3 destroyed (total: 11)&lt;br /&gt;
SortTracer generation 2 destroyed (total: 10)&lt;br /&gt;
SortTracer #14, copied as generation 2 (total: 11)&lt;br /&gt;
SortTracer comparison #5 (generation 2 &amp;lt; 1)&lt;br /&gt;
SortTracer #15, copied as generation 3 (total: 12)&lt;br /&gt;
SortTracer comparison #6 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #5 (generation 1 = 1)&lt;br /&gt;
SortTracer comparison #7 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #6 (generation 1 = 3)&lt;br /&gt;
SortTracer generation 3 destroyed (total: 11)&lt;br /&gt;
SortTracer generation 2 destroyed (total: 10)&lt;br /&gt;
SortTracer #16, copied as generation 2 (total: 11)&lt;br /&gt;
SortTracer comparison #8 (generation 2 &amp;lt; 1)&lt;br /&gt;
SortTracer #17, copied as generation 3 (total: 12)&lt;br /&gt;
SortTracer comparison #9 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #7 (generation 1 = 1)&lt;br /&gt;
SortTracer comparison #10 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #8 (generation 1 = 1)&lt;br /&gt;
SortTracer comparison #11 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #9 (generation 1 = 1)&lt;br /&gt;
SortTracer comparison #12 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #10 (generation 1 = 3)&lt;br /&gt;
SortTracer generation 3 destroyed (total: 11)&lt;br /&gt;
SortTracer generation 2 destroyed (total: 10)&lt;br /&gt;
SortTracer #18, copied as generation 2 (total: 11)&lt;br /&gt;
SortTracer comparison #13 (generation 2 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #11 (generation 1 = 1)&lt;br /&gt;
SortTracer assignment #12 (generation 1 = 1)&lt;br /&gt;
SortTracer assignment #13 (generation 1 = 1)&lt;br /&gt;
SortTracer assignment #14 (generation 1 = 1)&lt;br /&gt;
SortTracer assignment #15 (generation 1 = 1)&lt;br /&gt;
SortTracer assignment #16 (generation 1 = 2)&lt;br /&gt;
SortTracer generation 2 destroyed (total: 10)&lt;br /&gt;
SortTracer #19, copied as generation 2 (total: 11)&lt;br /&gt;
SortTracer comparison #14 (generation 2 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #17 (generation 1 = 1)&lt;br /&gt;
SortTracer assignment #18 (generation 1 = 1)&lt;br /&gt;
SortTracer assignment #19 (generation 1 = 1)&lt;br /&gt;
SortTracer assignment #20 (generation 1 = 1)&lt;br /&gt;
SortTracer assignment #21 (generation 1 = 1)&lt;br /&gt;
SortTracer assignment #22 (generation 1 = 1)&lt;br /&gt;
SortTracer assignment #23 (generation 1 = 2)&lt;br /&gt;
SortTracer generation 2 destroyed (total: 10)&lt;br /&gt;
SortTracer #20, copied as generation 2 (total: 11)&lt;br /&gt;
SortTracer comparison #15 (generation 2 &amp;lt; 1)&lt;br /&gt;
SortTracer #21, copied as generation 3 (total: 12)&lt;br /&gt;
SortTracer comparison #16 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #24 (generation 1 = 1)&lt;br /&gt;
SortTracer comparison #17 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #25 (generation 1 = 1)&lt;br /&gt;
SortTracer comparison #18 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #26 (generation 1 = 1)&lt;br /&gt;
SortTracer comparison #19 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #27 (generation 1 = 1)&lt;br /&gt;
SortTracer comparison #20 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #28 (generation 1 = 1)&lt;br /&gt;
SortTracer comparison #21 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #29 (generation 1 = 1)&lt;br /&gt;
SortTracer comparison #22 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #30 (generation 1 = 3)&lt;br /&gt;
SortTracer generation 3 destroyed (total: 11)&lt;br /&gt;
SortTracer generation 2 destroyed (total: 10)&lt;br /&gt;
SortTracer #22, copied as generation 2 (total: 11)&lt;br /&gt;
SortTracer comparison #23 (generation 2 &amp;lt; 1)&lt;br /&gt;
SortTracer #23, copied as generation 3 (total: 12)&lt;br /&gt;
SortTracer comparison #24 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #31 (generation 1 = 3)&lt;br /&gt;
SortTracer generation 3 destroyed (total: 11)&lt;br /&gt;
SortTracer generation 2 destroyed (total: 10)&lt;br /&gt;
SortTracer #24, copied as generation 2 (total: 11)&lt;br /&gt;
SortTracer comparison #25 (generation 2 &amp;lt; 1)&lt;br /&gt;
SortTracer #25, copied as generation 3 (total: 12)&lt;br /&gt;
SortTracer comparison #26 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #32 (generation 1 = 1)&lt;br /&gt;
SortTracer comparison #27 (generation 3 &amp;lt; 1)&lt;br /&gt;
SortTracer assignment #33 (generation 1 = 3)&lt;br /&gt;
SortTracer generation 3 destroyed (total: 11)&lt;br /&gt;
SortTracer generation 2 destroyed (total: 10)&lt;br /&gt;
---[ End std::sort() ]----------------------&lt;br /&gt;
0 1 2 3 4 5 6 7 8 9&lt;br /&gt;
std::sort() of 10 SortTracer&amp;quot;s was performed by:&lt;br /&gt;
 15 temporary tracers&lt;br /&gt;
 up to 12 tracers at the same time (10 before)&lt;br /&gt;
 33 assignments&lt;br /&gt;
 27 comparisons&lt;br /&gt;
SortTracer generation 1 destroyed (total: 9)&lt;br /&gt;
SortTracer generation 1 destroyed (total: 8)&lt;br /&gt;
SortTracer generation 1 destroyed (total: 7)&lt;br /&gt;
SortTracer generation 1 destroyed (total: 6)&lt;br /&gt;
SortTracer generation 1 destroyed (total: 5)&lt;br /&gt;
SortTracer generation 1 destroyed (total: 4)&lt;br /&gt;
SortTracer generation 1 destroyed (total: 3)&lt;br /&gt;
SortTracer generation 1 destroyed (total: 2)&lt;br /&gt;
SortTracer generation 1 destroyed (total: 1)&lt;br /&gt;
SortTracer generation 1 destroyed (total: 0)&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>