Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stian Jakobsen
DTE-3603 Template Source Base
Commits
a46da0bd
Commit
a46da0bd
authored
Aug 24, 2021
by
Stian Jakobsen
Browse files
functioning binary sort
parent
a5d2bf32
Changes
5
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
a46da0bd
...
...
@@ -19,6 +19,12 @@
*.cbp
*.autosave
#########
# Vscode
.vscode
.vscode/settings.json
########
## CMake
CMakeCache.txt
...
...
.vscode/settings.json
View file @
a46da0bd
...
...
@@ -14,6 +14,7 @@
"streambuf"
:
"cpp"
,
"tuple"
:
"cpp"
,
"type_traits"
:
"cpp"
,
"utility"
:
"cpp"
"utility"
:
"cpp"
,
"chrono"
:
"cpp"
}
}
\ No newline at end of file
day1_2_sort/include/day1_2_sort/binary_sort.h
View file @
a46da0bd
...
...
@@ -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
...
...
day1_2_sort/include/day1_2_sort/counting_sort.h
View file @
a46da0bd
...
...
@@ -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
}
}
...
...
day1_2_sort/include/day1_2_sort/radix_sort.h
View file @
a46da0bd
...
...
@@ -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
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment