1  #include <iostream>
  2  #include <string>
  3  using namespace std;
  4  
  5  template<typename T>
  6  void sort(T list[], int listSize) 
  7  {
  8    for (int i = 0; i < listSize; i++) 
  9    {
 10      // Find the minimum in the list[i..listSize-1]
 11      T currentMin = list[i];
 12      int currentMinIndex = i;
 13  
 14      for (int j = i + 1; j < listSize; j++) 
 15      {
 16        if (currentMin > list[j]) 
 17        {
 18          currentMin = list[j];
 19          currentMinIndex = j;
 20        }
 21      }
 22  
 23      // Swap list[i] with list[currentMinIndex] if necessary;
 24      if (currentMinIndex != i) 
 25      {
 26        list[currentMinIndex] = list[i];
 27        list[i] = currentMin;
 28      }
 29    }
 30  }
 31  
 32  template<typename T>
 33  void printArray(const T list[], int listSize)
 34  {
 35    for (int i = 0; i < listSize; i++)
 36    {
 37      cout << list[i] << " ";
 38    }
 39    cout << endl;
 40  }
 41  
 42  int main()
 43  {
 44    int list1[] = {3, 5, 1, 0, 2, 8, 7};
 45    sort(list1, 7);
 46    printArray(list1, 7);
 47  
 48    double list2[] = {3.5, 0.5, 1.4, 0.4, 2.5, 1.8, 4.7};
 49    sort(list2, 7);
 50    printArray(list2, 7);
 51  
 52    string list3[] = {"Atlanta", "Denver", "Chicago", "Dallas"};
 53    sort(list3, 4);
 54    printArray(list3, 4);
 55  
 56    return 0;
 57  }