#include <iostream>
#include <iomanip>
Go to the source code of this file.
◆ main()
Definition at line 10 of file sort.cpp.
   11{
   12    const int arraySize = 6;  
   13    int a[ arraySize ] = {-2, 7, 0, 23, 2048, -46};    
 
   14 
   15    cout << "Original array:\n";
   17 
   19 
   20    cout << "Sorted array:\n";
   22 
   23    return 0;
   24}
void print_array(const int[], int)
 
 
References print_array(), and sort().
 
 
◆ print_array()
      
        
          | void print_array  | 
          ( | 
          const int |           array[],  | 
        
        
           | 
           | 
          int |           sizeOfArray ) | 
        
      
 
Definition at line 27 of file sort.cpp.
   28{
   29    for ( int i = 0; i < sizeOfArray; ++i )
   30        cout << "[" << setw(2) << i << "] ";
   31    cout << endl;
   32 
   33    for ( int i = 0; i < sizeOfArray; ++i )
   34        cout << setw(3) << array[i] << "  ";
   35    cout << endl;
   36}
 
Referenced by main().
 
 
◆ sort()
      
        
          | void sort  | 
          ( | 
          int |           array[],  | 
        
        
           | 
           | 
          int |           sizeOfArray ) | 
        
      
 
Definition at line 40 of file sort.cpp.
   41{
   42    int i, j, idx;
   43    int min;
   44 
   45    for ( i = 0; i < sizeOfArray; ++i )
   46    {
   47        min = array[i];
   48        idx = i;
   49        for ( j = i + 1; j < sizeOfArray; ++j )
   50        {
   51            if ( array[j] < min )
   52            {
   53                min = array[j];
   54                idx = j;
   55            }
   56        }
   57        if ( idx != i )
   58            swap( array[i], array[idx] );   
 
   59    }
   60}
 
References swap().
Referenced by main().
 
 
◆ swap()
      
        
          | void swap  | 
          ( | 
          int & |           a,  | 
        
        
           | 
           | 
          int & |           b ) | 
        
      
 
Definition at line 62 of file sort.cpp.
   63{
   66     b = tmp;
   67     return;
   68}
 
Referenced by sort().