Commit a46da0bd authored by Stian Jakobsen's avatar Stian Jakobsen
Browse files

functioning binary sort

parent a5d2bf32
......@@ -19,6 +19,12 @@
*.cbp
*.autosave
#########
# Vscode
.vscode
.vscode/settings.json
########
## CMake
CMakeCache.txt
......
......@@ -14,6 +14,7 @@
"streambuf": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp"
"utility": "cpp",
"chrono": "cpp"
}
}
\ No newline at end of file
......@@ -14,13 +14,14 @@ namespace dte3603::sort::algorithms
void binary_sort(Iterator_T begin, Sentinel_T end,
Compare_T /*comp*/ = Compare_T())
{
auto max = std::max_element(begin, end);
auto min = std::min_element(begin, end);
auto size = max - min;
// Binary insertion sort using temp iterator to "move and insert"
// iterate for size of collection
// get selected item, location of item through binary search
// std::next(begin) or something until at the position of the final location of item and insert
for (Iterator_T temp = begin; temp != end; ++temp){
auto first = std::lower_bound(begin, temp, *temp); // Finding the first element of the range (binary search)
auto n_first = temp; // finding the first element of rotated range
auto last = std::next(temp); // finding the last element of the range by "advancing" the temp iterator
std::rotate(first, n_first, last); // rotating the range making n_first is the first element and n_first becomes last
}
}
} // namespace dte3603::sort::algorithms
......
......@@ -14,13 +14,6 @@ namespace dte3603::sort::algorithms
void counting_sort(Iterator_T begin, Sentinel_T end,
Compare_T /*comp*/ = Compare_T())
{
auto max = std::max_element(begin, end);
auto min = std::min_element(begin, end);
auto size = max - min;
int temp[size + 1] = {0}; // array of maximum value + 1
// output array of same length as input
}
}
......
......@@ -11,9 +11,12 @@ namespace dte3603::sort::algorithms
template <std::random_access_iterator Iterator_T,
std::random_access_iterator Sentinel_T,
typename Compare_T = std::less<> >
void radix_sort(Iterator_T /*begin*/, Sentinel_T /*end*/,
void radix_sort(Iterator_T begin, Sentinel_T end,
Compare_T /*comp*/ = Compare_T())
{
// Getting the max element
auto max = *std::max_element(begin, end);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment