Anúncio
Write the selection sort algorithm for an array of int in C++- You are.docx
Write the selection sort algorithm for an array of int in C++- You are.docx
Próximos SlideShares
Microsoft word   javaMicrosoft word java
Carregando em ... 3
1 de 2
Anúncio

Mais conteúdo relacionado

Mais de karlynwih(20)

Anúncio

Write the selection sort algorithm for an array of int in C++- You are.docx

  1. Write the selection sort algorithm for an array of int in C++. You are to assume that there are predefined functions swapValues and indexOfSmallest, that is do not write these functions. However, you must write declarations with pre and post conditions for these functions. Solution /********************************************************** * Function: swapValues * Description: Swaps two values **********************************************************/ template <class T> void swapValues(T &v1, T &v2) { T temp; temp = v1; v1 = v2; v2 = temp; } /********************************************************** * Function: indexOfSmallest * Description: Finds the smallest value in the array *Â Â and returns its index. **********************************************************/ template <class T> int indexOfSmallest(const T array[], int startIndex, int size) { T min = array[startIndex]; int indexOfMin = startIndex; for (int index = startIndex + 1; index < size; index++) { if (array[index] < min) { min = array[index]; indexOfMin = index;
  2. } } return indexOfMin; }
Anúncio