-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
feat: add hybrid quick-insertion-selection sorting algorithm with tests #2956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try not to use the raw array and instead opt for either std::vector incase you want an array of dynamic length or std::array if the size is known at compile time
#include <algorithm> // for std::is_sorted | ||
#include <cassert> // for assert | ||
#include <iostream> // for IO | ||
#include <vector> // for vector in test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <algorithm> // for std::is_sorted | |
#include <cassert> // for assert | |
#include <iostream> // for IO | |
#include <vector> // for vector in test | |
#include <algorithm> /// for std::is_sorted | |
#include <cassert> /// for assert | |
#include <iostream> /// for IO | |
#include <vector> /// for vector in test |
* sorts the left half with insertion sort | ||
* sorts the right half with selection sort | ||
* created for educational purposes not optimized for speed. | ||
* @author Cesar (https://github.com/cesar-011) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @author Cesar (https://github.com/cesar-011) | |
* @author [Cesar](https://github.com/cesar-011) |
/** | ||
* @brief swap two elements of an array | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* @brief swap two elements of an array | |
*/ | |
/** | |
* @brief swap two elements of an array | |
* @tparam T | |
* @param arr | |
* @param i | |
* @param j | |
*/ |
/** | ||
* @brief print the array | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* @brief print the array | |
*/ | |
/** | |
* @brief print the array | |
* @tparam T | |
* @param arr | |
* @param size | |
*/ |
|
||
// An example | ||
int N = 8; | ||
int array[N] = {8, 5, 9, 20, 2, 13, 3, 1}; | ||
print_array(array, N); | ||
std::cout << '\n'; | ||
sorting::hybrid_quick_insert_select::hybrid_quick_insertion_selection(array, | ||
0, N); | ||
print_array(array, N); | ||
std::cout << '\n'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// An example | |
int N = 8; | |
int array[N] = {8, 5, 9, 20, 2, 13, 3, 1}; | |
print_array(array, N); | |
std::cout << '\n'; | |
sorting::hybrid_quick_insert_select::hybrid_quick_insertion_selection(array, | |
0, N); | |
print_array(array, N); | |
std::cout << '\n'; |
|
||
// Test 3: positive numbers | ||
{ | ||
std::vector<int> arr = {1, 2, 3, 4, 5}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for all your tests you use vectors and pass the data, You could've instead designed the functions to work with vectors directly instead
Description of Change
Added a hybrid sorting algorithm combining QuickSort, Insertion Sort, and Selection Sort.
Included tests and example usage.
This implementation is for educational purposes and follows the project's style guidelines.
Checklist
Notes: "Hybrid of QuickSort, Insertion Sort, and Selection Sort for educational purposes, not optimized for speed."