A rust library to sort vectors (containing any type of elements) with classes that are iterators.
With this library it will be easy to understand how some algorithms work step-by-step.
There are three categories of algorithm. Each category is represented by an enum in the code:
- SortingPosHighlight (CycleSort, PancakeSort): Algorithms that return the index of the element that they are moving;
- SortingPairPosHighlight (HeapSort, MergeSort): Algorithms that return a pair of indexes that represents the range that they are working on;
- SortingElemGiven (SleepSort, StalinSort): Algorithms that return the element itself;
There also is BogoSort which isn't part of the above-mentioned categories.
- Add the algorithm.rs file to the sortingalgorithms folder;
- (Optional) Add the respective class to one of the enums;
- Add a call to the macro that you think fits best at the end of the
mod sortingalgorithms
block;
To use the algorithms simply implement the VectorElement
trait for the type that you are going to use.
After this using the get_sorting_iterator(EnumElement, vector, comparator)
or by calling new()
on the class of the
iterator you are interested in you can get an instance.
The next step is to call the .next()
method and see what element the algorithm is working on.
If you want to use a non user-defined type like i32 you have to make a wrapper for it, for more information look
example1 inside examples/ folder
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.