Skip to content
Add a stalin sort algorithm in any language you like ❣️ if you like give us a ⭐️
Python Scala C++ Assembly C# Rust Other
Branch: master
Clone or download
Latest commit 08a6e19 Aug 23, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
C++ add printer Aug 6, 2019
C Adding Stalin Sort in C Language Oct 30, 2018
DM Actually O(n) but drops assoc values. Aug 1, 2019
Delphi Changed "<" -> "<=" Aug 3, 2019
MATLAB A MATLAB implementation Aug 2, 2019
awk add bash & awk Aug 1, 2019
bash add bash & awk Aug 1, 2019
brainfuck Add brainfuck implementation Nov 12, 2018
c# Merge pull request #58 from RobThree/master Aug 3, 2019
clojure Added "strict" version Jul 31, 2019
common-lisp Create salin-sort-loop.lisp Aug 1, 2019
crystal Create stalin_sort.cr Aug 5, 2019
dart Update stalin_sort.dart Aug 2, 2019
elixir Add Elixir version Aug 1, 2019
elm Fix equals number case Aug 2, 2019
erlang Add Erlang implementation Jul 30, 2019
f# F# implementation. Aug 23, 2019
fetlang Allow equality in fetlang implementation Aug 7, 2019
go add benchmark Aug 19, 2019
gp Added PARI/GP implementation of Stalin Sort. Nov 9, 2018
haskell Renamed general StalinSort Haskell implementation as requested Aug 6, 2019
haxe better haxe implementation Jul 30, 2019
java Merge branch 'master' into master Aug 7, 2019
javascript Update javascript/stalin-sort.js Jul 31, 2019
julia added examples as comments Aug 2, 2019
kotlin improve kotlin stalin sort speed Jul 31, 2019
lua add lua file Jul 31, 2019
mips implemented stalin-sort in 32-bit mips assembly Aug 19, 2019
moonscript Removed testing suite and added a table export Aug 1, 2019
ocaml Add ocaml implementation Jul 31, 2019
perl readability Jul 31, 2019
php Add PHP version of Stalin sort Jul 30, 2019
python Merge pull request #52 from watosar/patch-1 Aug 7, 2019
r added additional test case Aug 2, 2019
reason fix indentation Aug 7, 2019
ruby Add a recursive stalin_sort implementation in ruby Aug 2, 2019
rust Update pattern_match.rs Aug 7, 2019
scala Merge pull request #54 from pamu/master Aug 18, 2019
scheme Merge pull request #69 from chaw/master Aug 2, 2019
sh Bourne shell implementation Aug 2, 2019
shen Add Stalin Sort in Shen Jul 31, 2019
sml Add Standard ML implementation. Jul 30, 2019
swift fix a small bug when the array has consecutive same value Aug 1, 2019
typescript Update stalin-sort.ts Aug 2, 2019
vb.net Got rid of solution files and left program.VB ready for PR Aug 2, 2019
vimscript list can contain repeated numbers Aug 8, 2019
CONTRIBUTING.md Update CONTRIBUTING.md Aug 3, 2019
LICENSE Update LICENSE Aug 5, 2019
readme.md Update readme.md Aug 20, 2019
stalin-sort.jpeg readme Oct 30, 2018

readme.md

Welcome to the Stalin Sort Repo 📋

poster

What is Stalin Sort?

Introduction

Stalin Sort is an efficient sorting algorithm, serving as a systematic method for placing the elements of a random access file or an array in order. Stalin Sort is also know as the best sorting algorithm of all times becasue of it's AMAZING capacity of always ordering an array with an O(n) performance.

How it works?

It's simple, all you need to do is iterate through the array checking if its elements are in order, any element that itsn't in order you pull out, in another words, you send it to Gulag.

Step-by-step example

  1. (1 2 5 3 5 7) -> (1 2 5 3 5 7) Here the algorithm stores the first of element of the array
  2. (1 2 5 3 5 7) -> (1 2 5 3 5 7) Now it will compare the stored element with the second one, if this is bigger than the stored, it replaces the stored element by this
  3. (1 2 5 3 5 7) -> (1 2 5 3 5 7) Repeats step 2
  4. (1 2 5 3 5 7) -> (1 2 5 5 7) Since the 4th element is smaller then the 3rd one that is just eliminated
  5. (1 2 5 5 7) -> (1 2 5 5 7) Equal elements are preserved
  6. (1 2 5 5 7) Ordered array!

Pseudocode implementation

Have in mind that this pseudocode is just an example, we strongly encourage you to code a different approach.

FUNCTION stalinSort(A : list OF sortable items)
    n := length(A)
    bigger := 0
    B SET empty list

    FOR i := 0 TO n NOT inclusive DO
        IF A[i] >= bigger THEN
          bigger := A[i]
          B.push(A[i])
        END IF
    END FOR

    RETURN B
END FUNCTION

Want to help? 🙌

Please check the CONTRIBUTING.md

Give this Project a Star! ⭐️

About

Stalin sort began first as a Hacktoberfest 2018 repo

Hacktoberfest is a program organised by Digital Ocean and Github, where you can easily win a T-Shirt just by making 5 pull requests in the month of October to any open source projects on Github.

You can’t perform that action at this time.