add namespace - sorting

This commit is contained in:
Krishna Vedala 2020-05-31 23:00:59 -04:00
parent 1125c85b3f
commit c2c4681554

View File

@ -1,11 +1,17 @@
/**
* \file
* \brief [Shell sort](https://en.wikipedia.org/wiki/Shell_sort) algorithm
*/
#include <array> #include <array>
#include <cstdlib> #include <cstdlib>
#include <ctime> #include <ctime>
#include <iostream> #include <iostream>
#include <utility> // for std::swap
// for std::swap /** pretty print array
#include <utility> * \param[in] arr array to print
* \param[in] LEN length of array to print
*/
template <class T> template <class T>
void show_data(T *arr, size_t LEN) { void show_data(T *arr, size_t LEN) {
size_t i; size_t i;
@ -14,11 +20,19 @@ void show_data(T *arr, size_t LEN) {
std::cout << std::endl; std::cout << std::endl;
} }
/** pretty print array
* \param[in] arr array to print
* \param[in] N length of array to print
*/
template <class T, size_t N> template <class T, size_t N>
void show_data(T (&arr)[N]) { void show_data(T (&arr)[N]) {
show_data(arr, N); show_data(arr, N);
} }
/** \namespace sorting
* \brief Sorting algorithms
*/
namespace sorting {
/** /**
* Optimized algorithm - takes half the time by utilizing * Optimized algorithm - takes half the time by utilizing
* Mar * Mar
@ -42,11 +56,17 @@ void shell_sort(T *arr, size_t LEN) {
} }
} }
/** function overload - when input array is of a known length array type
*/
template <class T, size_t N> template <class T, size_t N>
void shell_sort(T (&arr)[N]) { void shell_sort(T (&arr)[N]) {
shell_sort(arr, N); shell_sort(arr, N);
} }
} // namespace sorting
using sorting::shell_sort;
/** /**
* function to compare sorting using cstdlib's qsort * function to compare sorting using cstdlib's qsort
**/ **/