A simple yet effective sorting algorithm in C++
using templates to support both vectors and arrays.
- Template-based implementation
- Two distinct sorting implementations:
vector_sort
: Specialized for std::vectortype_sort
: Works with standard arrays
- Simple selection sort algorithm
- Header-only implementation
- Namespace organization for clean code structure
#include "sort.h"
#include <iostream>
// Vector sorting example
void vectorExample()
{
std::vector<uint32_t> nums = { 1, 7, 3, 8, 2 };
std::vector<uint32_t> sorted = Hollow::vector_sort::sort(nums);
for (int i = 0; i < nums.size(); i++)
{
printf("%d%s", sorted[i], " ");
}
}
// Array sorting example
void arrayExample()
{
char arr[] = { 'a', 'c', 'f', 'b' };
int size = sizeof(arr) / sizeof(arr[0]);
Hollow::type_sort::sort(arr, size);
for (int i = 0; i < size; i++)
{
std::cout << arr[i] << " ";
}
}
- Download
sort.h
- Add it to your project
- Include the header:
#include "sort.h"
git clone https://github.com/Ho11ow1/Sorting_algorithm
- Ensure
sort.h
is in your include path - Check C++ version compatibility
- Verify STL is available