Skip to content

A rust library to sort vectors (containing any type of elements) with classes that are iterators.

License

Notifications You must be signed in to change notification settings

Odinmylord/SortingIterators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Sorting Iterators

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.

Algorithms

Categories

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.

How to add an algorithm

  • 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;

Usage

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

License

Shield: CC BY-SA 4.0

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

CC BY-SA 4.0

About

A rust library to sort vectors (containing any type of elements) with classes that are iterators.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages