I would like to look at the source code for the Timsort sorting algorithm written in Java or C #.
2 answers
If the code timsort (and heaps of other sorts) on C is interesting , then swenson / sort is a very worthy place. The project README describes in some detail how to use it.
(undoubtedly, stable is also of interest there (as well as timsort ) the merge sort version with additional memory is only O (sqrt (N)), called SQRT_SORT )
You can also see yamsort - another attempt to implement a stable merge sort with a small (5-10% of N ( 5 years ago SQRT_SORT was not yet! )) Additional memory in C. The template-style implementation is yamsort_tmpl.h (usage example, for example, data_yamsort.c ).
In the same project, along with the timsort code in the template-style, you can see the timsort code (mainly taken from swenson/sort ) with an interface similar to the well-known qcort libc function
(an example of use there, in measure.c and Makefile ).
- Thank you for the useful resources)) - Trapping
For example, Java uses TimSort, and it can be viewed in the Java source .
The code, unfortunately, does not fit in response. Note that this implementation is licensed under the GPL, so you really can only see (if you don’t write the GPL project yourself).
Here is a variant with documentation and hyperlinks .
- one@Trapping Now you can open the following new question about something like this: "I looked at the source code of the Timsort sorting algorithm written in Java, but I still have questions. Could someone write for me my code based on this code?" :) - Vlad from Moscow
- @VladfromMoscow it is a pity that you have such an opinion about me, probably I’m not the best way to show myself asking such questions. By the way, the moment that I did not understand was found in this documentation. The problem was that I did not understand the principle of forming a stack with an already sorted part of the array. - Trapping
- @VladD thanks for the reply. Very helpful. - Trapping
- @Trapping: Please! Good luck! - VladD
- one@Trapping, The problem was that I did not understand the principle of forming a stack with an already sorted part of the array. - it was about this and it was necessary to ask - Grundy