1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <iostream>
#include <utility>
constexpr size_t SIZE { 8 };
template <class T>
void numDisplay(const T array[], size_t size) {
for (size_t numbers {}; numbers < size; ++numbers)
std::cout << array[numbers] << " ";
std::cout << '\n';
}
template <class T>
void numSort(T array[], size_t size) {
for (size_t counter {}; counter < size - 1; ++counter)
for (size_t track { counter + 1 }; track < size; ++track)
if (array[counter] > array[track])
std::swap(array[counter], array[track]);
}
int main() {
int numArray[SIZE] { 1, 12, 34, 56, 11, 15, 18, 20 };
std::cout << "The values stored in the integer table: ";
numDisplay(numArray, 8);
std::cout << "The numbers sorted in the integer table: ";
numSort(numArray, 8);
numDisplay(numArray, 8);
double floatArray[SIZE] { -9.0, 2.3, 1.3, 5.6, 7.8, 6.8, 12.0, 15.6 };
std::cout << "The values stored in the floating table: ";
numDisplay(floatArray, 8);
std::cout << "The numbers sorted in the floating table: ";
numSort(floatArray, 8);
numDisplay(floatArray, 8);
}
|