[Question]
  [
Given a list of Integers greater than zero, Sort each of the unique values in ascending order, then repeat the process on the remaining duplicate values and append.
Example:
```
[1,5,2,2,8,3,5,2,9] ==> [1,2,3,5,8,9,2,5,2]
[8,5] ==> [5,8]
[2,2,2] ==> [2,2,2]
```
  
[Answer]
# [Haskell](https://www.haskell.org/), 44 bytes
```
import Data.List
concat.transpose.group.sort
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/PzO3IL@oRMElsSRRzyezuIQrzTY5Py85sUSvpCgxr7ggvzhVL70ov7RArxio7n9uYmaebUFRZl6JSlq0oY6pjhEQWugYg1mWsf8B "Haskell ‚Äì Try It Online") (has an extra 2 bytes for `f=`)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
·π¢≈ígZF
```
[Try it online!](https://tio.run/##y0rNyan8///hzkVHJ6VHuf3//99Qx1THCAgtdIzBLEsA "Jelly ‚Äì Try It Online")
A monadic link taking an unsorted list of integers and returning the list sorted as described.
## Explanation
```
·π¢     | Sort
 ≈íg   | Group runs of identical digits together
   Z  | Transpose
    F | Flatten
```
[Answer]
# [Uiua](https://uiua.org), 11 [bytes](https://codegolf.stackexchange.com/a/265917/97916)
```
‚ñΩ‚â†0.‚ô≠‚çâ‚¨ö0‚äï‚àò.
```
[Try it!](https://uiua.org/pad?src=0_6_1__ZiDihpAg4pa94omgMC7ima3ijYnirJow4oqV4oiYLgoKZiBbMSA1IDIgMiA4IDMgNSAyIDldCmYgWzEgMSAyIDIgMyAzXQpmIFsxIDIgMiAzIDMgM10KZiBbMV0KZiBbXQo=)
* `.` duplicate input
[![enter image description here](https://i.stack.imgur.com/DehWp.png)](https://i.stack.imgur.com/DehWp.png)
* `‚¨ö0‚äï‚àò` group by identity, filling with zeros
[![enter image description here](https://i.stack.imgur.com/bXvrh.png)](https://i.stack.imgur.com/bXvrh.png)
* `‚çâ` transpose
[![enter image description here](https://i.stack.imgur.com/BqDLS.png)](https://i.stack.imgur.com/BqDLS.png)
* `‚ô≠` deshape
[![enter image description here](https://i.stack.imgur.com/gGsvW.png)](https://i.stack.imgur.com/gGsvW.png)
* `‚ñΩ‚â†0.` keep non-zeros
[![enter image description here](https://i.stack.imgur.com/7kQ7k.png)](https://i.stack.imgur.com/7kQ7k.png)
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal/tree/version-2), 28 [bitsv2](https://github.com/Vyxal/Vyncode/blob/main/README.md), 3.5 bytes
```
sƒ†‚à©f
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2&c=1#WyI9IiwiIiwic8Sg4oipZiIsIiIsIlsxLDUsMiwyLDgsMyw1LDIsOV0iXQ==)
Bitstring:
```
1000100001100101100111101000
```
Port of the Uiua answer except without the 0 filling because it's not needed here. And they say having a fixed array model is a good thing! :p
## Explained
```
sƒ†‚à©f¬≠‚Å°‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å°‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å¢‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å£‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å§‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å§‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå¬≠
s     # ‚Äé‚Å°Sort the input
 ƒ†    # ‚Äé‚Å¢Group on consecutive items
  ‚à©   # ‚Äé‚Å£Transpose
   f  # ‚Äé‚Å§and flatten
üíé
```
Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
[Answer]
# [Nekomata](https://github.com/AlephAlpha/Nekomata) + `-1`, 5 bytes
```
oO·µê≈Øj
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iLzU7PzexJHFNtJJurpKOgpKuoVLsgqWlJWm6Fivy_R9unXB0fdaS4qTkYqjggpuK0YY6pjpGQGihYwxmWcZyRZvoACGQttAxjYWoBAA)
```
oO·µê≈Øj
o       Sort
 O      Find a set partition
  ·µê≈Ø    such that no part contains duplicates
    j   Join
```
The flag `-1` finds only the first solution.
The built-in `O` (`\setPartition`) uses the following algorithm (taken from [Curry's Combinatorial package](https://cpm.curry-lang.org/DOC/combinatorial-3.0.0/Combinatorial_curry.html#partition)), which ensures that the first solution is exactly the one we want:
```
partition    :: [a] -> [[a]]
partition [] = []
partition (x:xs) = insert x (partition xs)
    where insert e [] = [[e]]
          insert e (y:ys) = ((e:y):ys) ? (y:insert e ys)
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
ƒ†ZF·ªã
```
A monadic Link that accepts a list and yields the "sorted" list.
**[Try it online!](https://tio.run/##y0rNyan8///Igii3h7u7////H22oY6pjBIQWOsZglmUsAA "Jelly ‚Äì Try It Online")**
### How?
```
ƒ†ZF·ªã - Link: list A            e.g. [8,8,8,3,7,7,3,3]
ƒ†    - Group indices of A by value  [[4,7,8],[5,6],[1,2,3]]
 Z   - transpose                    [[4,5,1],[7,6,2],[8,3]]
  F  - flatten                      [4,5,1,7,6,2,8,3]
   ·ªã - index into A                 [3,7,8,3,7,8,3,8]
```
[Answer]
# [R](https://www.r-project.org/), 40 bytes
```
function(x)x[order(ave(!x,x,FUN=seq),x)]
```
[Try it online!](https://tio.run/##K/qfpmCj@z@tNC@5JDM/T6NCsyI6vygltUgjsSxVQ7FCp0LHLdTPtji1UFOnQjP2f5pGsoahjqmOERBa6BiDWZaamlxpGpl5JanpQH0Gmpr/AQ "R ‚Äì Try It Online")
Shorter to use `order` than `split`.
# [R](https://www.r-project.org/), 55 bytes
```
function(x,y=sort(x))unlist(split(y,ave(!y,y,FUN=seq)))
```
[Try it online!](https://tio.run/##K/qfpmCj@z@tNC@5JDM/T6NCp9K2OL@oRKNCU7M0LyezuESjuCAns0SjUiexLFVDsVKnUsct1M@2OLVQU1Pzf5pGsoahjqmOERBa6BiDWZaamlxpGpl5JanpqUUaBkBVAA "R ‚Äì Try It Online")
Noticed the `split` and `ave` characterization about 2 minutes after posting the longer answer below. Rough R equivalent to the Jelly answer.
# [R](https://www.r-project.org/), 73 bytes
```
f=function(x,o={},d=duplicated(x))'if'(sum(x),f(x[d],c(o,sort(x[!d]))),o)
```
[Try it online!](https://tio.run/##HccxCgIxEEbh3ltY7fwwha4IWuQkssWSyUhAM5JNICCePYblNd/LvavTmnyJlqixue@PxUn9vKJfSxBqwBR1oq2@h1mpPWRhT8ab5TLuKAsANnQlT2e@8jy68WXXHTgoxVTCM2Q6Af0P "R ‚Äì Try It Online")
Naive implementation: sort unique values and recurse on remainder, appending as you go. Probably there's a shorter way.
[Answer]
# [Haskell](https://www.haskell.org/), ~~62~~ 52 bytes
```
import Data.List
f[]=[]
f x|z<-sort$nub x=z++f(x\\z)
```
[Try it online!](https://tio.run/##PYvLCoMwFET3@YpZdGHotVBbQcHsuuwfxCzSYmioL0wKIv67jfbBbM6cO/eh3bOq62WxTd8NHhft9eFqnWdGKiEVMxjnqYhdOO7a1w2jmPZ7E41lOfGl0baFQD/Y1kMaWAiBDjMiS@g4ihi@cv6uXeUUY38OP5IBkTxSSklIRqeNckUIMtlqRnmgoBWnbX2mkHXxga/NKF1d2P/MWhVXbHkD "Haskell ‚Äì Try It Online")
[Answer]
# [J](http://jsoftware.com/), 13 bytes
```
/:],.~1#.]=]\
```
[Try it online!](https://tio.run/##RYvBCsIwEETv/YqhHmrtdjdRhHYhEBQ8iQevNqdiES/@gOTXY1oUGQYeb5hnKrma4BQVCAaa2zKO1/MpiQbiaFccXBhSXVwOjLXoV9ReNP7cTRtxm0aG0nr3X0zL0ZB/axCOiy3u4@OFCZb2tM3paLdQD8wHm3EWHfWZ8pA@ "J ‚Äì Try It Online")
* `/:` Sort by
* `1#.]=]\` Running sum count of each unique value *first*
* `,.~` Followed by
* `]` The original value
That is, we form pairs `<running count for this value, this value>` and sort by those pairs.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 45 bytes
Expects an `Uint16Array` filled with unsigned bytes and returns a `Buffer`.
```
a=>Buffer(a.map(o=v=>o[v]=o[v]+256|v).sort())
```
[Try it online!](https://tio.run/##HYnRCsIgGEZfxUt/MseMje3CQb1DV@KFLI3F8h9qRtC7m40PPg7nPEw2cQ7Llo4eb7Y4WYycLi/nbKCGP81GUWY5ocpa/u8guv6bgUcMiQKUGX3E1fIV71Rxzh319k2ui09tfw7BfKhqWcdE3cBOO40aQANpGlKT2OXAxko16vID "JavaScript (Node.js) ‚Äì Try It Online")
### Commented
```
a =>             // a[] = input Uint16Array
Buffer(          // coerce to bytes:
  a.map(o =      //   o = object to keep track of the number
                 //       of times each value appears
  v =>           //   for each value v in a[]:
    o[v] =       //     update o[v]:
      o[v] + 256 //       increment the high byte
                 //       (no effect on the 1st iteration)
      | v        //       use v as the low byte
  )              //   end of map()
  .sort()        //   sort the 16-bit values
)                // end of Buffer()
```
---
# JavaScript (ES6), 51 bytes
Expects an `Uint16Array` filled with unsigned bytes and returns an array in the same format.
(This version could be updated to support larger integers at the cost of a few extra bytes.)
```
a=>a.map(o=v=>o[v]=o[v]+256|v).sort().map(v=>v&255)
```
[Try it online!](https://tio.run/##HYpBCsMgFESv4qootYZYDMnCQA/RVXDxSU1JSfxBxVLo3a2VgeExb16QIMx@PeLF4cPmRWfQI4gdDoo66RGnZPS/zlJ138REQB8pq4ei00kqxfKMLuBmxYZPulBn3@S@uth2N@/hQ6eWKy5Len6tNBjGGGkaUoysW8@HQsWZ/AM "JavaScript (Node.js) ‚Äì Try It Online")
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), 6 bytes
```
‚çã‚àò‚äí‚ä∏‚äè‚àß
```
[Try it online!](https://mlochbaum.github.io/BQN/try.html#code=RiDihpAg4o2L4oiY4oqS4oq44oqP4oinCgoi8J2VqSLigL8iRvCdlaki4oi+4oi+4p+cKEbCqCnLmOKfqApbMSw1LDIsMiw4LDMsNSwyLDldLApbOCw1XSwKWzIsMl0sCuKfqDHin6ksCuKfqOKfqQrin6k=)
Or alternatively, [`‚àæ‚äí‚ä∏‚äî‚àò‚àß`](https://mlochbaum.github.io/BQN/try.html#code=RiDihpAg4oi+4oqS4oq44oqU4oiY4oinCgoi8J2VqSLigL8iRvCdlaki4oi+4oi+4p+cKEbCqCnLmOKfqApbMSw1LDIsMiw4LDMsNSwyLDldLApbOCw1XSwKWzIsMl0sCuKfqDHin6ksCuKfqOKfqQrin6k=)
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 38 bytes
```
mO$`(.+)(?<=((^\1$)|.|¬∂)*)
$#3$*1,$&$*
```
[Try it online!](https://tio.run/##K0otycxL/B@coPM/118lQUNPW1PD3sZWQyMuxlBFs0av5tA2TS1NLhVlYxUtQx0VNRWt/4e2cen8N9Qx1TECQgsdYzDLEgA "Retina 0.8.2 ‚Äì Try It Online") Takes input on separate lines but link splits on commas for convenience. Explanation: Sorts each value by a key made up of its occurrence count and value, expressed in unary.
@TwiNight's idea of sorting twice (since the sort is stable) saves 10 bytes, since the second sort doesn't have to guard against extraneous matches:
```
O#`
O#$`(.+)(?<=(¬∂?\1)+)
$#2
```
[Try it online!](https://tio.run/##K0otycxL/B@coPPfXzmBy19ZJUFDT1tTw97GVuPQNvsYQ01tTS4VZaP/h7Zx6fw31DHVMQJCCx1jMMsSAA "Retina 0.8.2 ‚Äì Try It Online") Takes input on separate lines but link splits on commas for convenience.
Note that each link can be turned into a test suite by prefixing `%(` to the header.
[Answer]
# [BQN (CBQN)](https://mlochbaum.github.io/BQN/), 10 bytes
```
{‚àæ‚àß¬®ùï©‚äîÀú‚äíùï©}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m704qTBvwdK0R20TqpeWlqTpWuyqftSx71HH8kMrPsyduvJR15TTcx51TQKxayEKbjrWcj1qWBSckV-u4KYQbahjqmMEhBY6xmCWZSyyrIkOEKKIWOiYxkIMWrAAQgMA)
[Answer]
# [Perl 5](https://www.perl.org/) `-MList::Util=uniq -a`, 59 bytes
```
map$t{$_}++,@F;1while@F=grep{say;--$t{$_}}sort{$a-$b}uniq@F
```
[Try it online!](https://tio.run/##K0gtyjH9/z83sUClpFolvlZbW8fBzdqwPCMzJ9XBzTa9KLWgujix0lpXFyJfW5xfBGQk6qok1ZbmZRY6uP3/b6hgqmAEhBYKxmCW5b/8gpLM/Lzi/7q@pnoGhgZA2iezuMTKKrQkM8cWpO2/biIA "Perl 5 ‚Äì Try It Online")
[Answer]
# [Retina](https://github.com/m-ender/retina), ~~30~~ 26 bytes
```
N`
N$`(.+)(?<=(¬∂?\1)+)
$#2
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72sKLUkMy9xwYKlpSVpuha7_RK4_FQSNPS0NTXsbWw1Dm2zjzHU1NbkUlE2WlKclFwMVbdgoyGXKZcREFpwGYNZlhAJAA)
Edit: -4 bytes thanks to Neil, by changing I/O format
Input and output are newline-separated decimals.
First sort normally, then sort (stably) again using the occurrence index
[Answer]
# [Ruby](https://www.ruby-lang.org/), 41 bytes
```
->l,*r{l.sort_by{|x|[(r<<x).count(x),x]}}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y5HR6uoOkevOL@oJD6psrqmoiZao8jGpkJTLzm/NK9Eo0JTpyK2tvZ/gUJadLShjqmOERBa6BiDWZaxsf8B "Ruby ‚Äì Try It Online")
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), 15 bytes
-2 bytes thanks to att.
```
{0~‚ç®,‚çâ‚ä£¬®‚å∏‚çµ[‚çã‚çµ]}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v8/7VHbhGqDuke9K3Qe9XY@6lp8aMWjnh2PerdGP@rtBlKxtUA1CoYKpgpGQGihYAxmWXKlAVlGQGwIoYF8ExAE0hYKpkDyUe8aHUMIDQA "APL (Dyalog Classic) ‚Äì Try It Online")
**Explanation**
```
{0~‚ç®,‚çâ‚ä£¬®‚å∏‚çµ[‚çã‚çµ]}¬≠‚Å°‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å°‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å°‚Å°‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å¢‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å§‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å§‚Å°‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å§‚Å¢‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å§‚Å£‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å§‚Å§‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å£‚Äã‚Äé‚Å™‚Å™‚Å†‚Å™‚Å™‚Å†‚Å™‚Å™‚Å†‚Å™‚Å™‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å£‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å§‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å¢‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å¢‚Å°‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å£‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å§‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å¢‚Å¢‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å£‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å§‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å°‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å¢‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å£‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å¢‚Å£‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å¢‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å¢‚Å§‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å°‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå‚Å£‚Å°‚Äã‚Äé‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å¢‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å£‚Å™‚Äè‚Å†‚Äé‚Å™‚Å°‚Å™‚Å†‚Å™‚Å§‚Å™‚Äè‚Äè‚Äã‚Å°‚Å†‚Å°‚Äå¬≠
{                 }  # ‚Äé‚Å°dfn
           ‚çµ[‚çã‚çµ]   # ‚Äé‚Å¢sort
       ‚ä£¬®‚å∏          # ‚Äé‚Å¢‚Å¢groups into matrix, padding with zeros
     ‚çâ              # ‚Äé‚Å¢‚Å£transpose
    ,                # ‚Äé‚Å¢‚Å§ravel (flatten)
 0~‚ç®                 # ‚Äé‚Å£‚Å°remove zeros
üíé
```
Created with the help of [Luminespire](https://vyxal.github.io/Luminespire).
I think that using a *dfn* rather than tacit is probably shorter here, since we are applying a bunch of monadic functions, and sorting is no shorter in tacit: `‚äÇ‚àò‚çã‚å∑‚ä¢`.
[Answer]
# [PowerShell Core](https://github.com/PowerShell/PowerShell), 73 bytes
```
$f={param($a)if($a){($g=$a|group).Name
&$f($g|%{,$_.Name*($_.Count-1)})}}
```
[Try it online!](https://tio.run/##bVDRaoMwFH3PVwTJ1mQkhToK9kEQpHvcxtq3MUrmUmvRxiWRDdRvd4midmMJhJNzzr33JKX8EkqfRJ6zRCrRdegY1iVXvMCIk@zozhqjNES8SZWsSrJ85IUAt8hKaXNTU3TomTtsQSyri2Er0pK27SIMoF0URthb0TX17Q7ofY82HoWW9PtrQDcWWdojc0VA185j1WvW9fAdPwACCGzgg1RbnpzY0/tZJAbWvR0ZoU3MtaAQie/SCuIDhhAdfquOmjDTZZ4ZuKALMLiU0FVurMc@d/b9FUfEzjK7zNWvz7u40kYWQ663aAjm1q5KEqE1dMVTOCY@x1bLvcoKTCb//t@007jR9jLkgHOmSdpefcE4sRdb0ILuBw "PowerShell Core ‚Äì Try It Online")
Recursive function  
Takes an array as a parameter  
Returns an array
### Explanation
```
param($a)                    # The array in variable $a
if($a){...}                  # If the array is empty, do nothing, otherwise:
($g=$a|group).Name           # Group the numbers in the array, store the groups in $g and return the unique elements sorted
$g|%{,$_.Name*($_.Count-1)}  # From the groups, rebuild a list with one element less for each elements
&$f(...)                     # Recursively invoke the function on the rebuilt list
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 5 bytes
```
o·∏Öz‚ÇÅc
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/P//hjtaqR02Nyf//RxvqmOoYAaGFjjGYZRn7PwoA "Brachylog ‚Äì Try It Online")
### Explanation
```
o        Sort in ascending order
 ·∏Ö       Group consecutive elements together
  z‚ÇÅ     Zip without cycling
    c    Concatenate
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 24 bytes
```
ÔºµÔº≠Œ∏‚ü¶‚Ññ‚Ä¶Œ∏Œ∫ŒπŒπ‚üßÔº∑‚ÅªŒ∏œÖ‚äûœÖ‚åäŒπÔº©Ôº•œÖ‚äüŒπ
```
[Try it online!](https://tio.run/##HY29CgIxEIR7nyLlBtbCE0GxTH2QPqQI8SDB/JyXW8WnjxsZFob5lhkf3OarS73PblU1Z1ce8EJhVKWyg/r6tKhQ15E9JYo4zsr74RNiWgTMsVAbkKQUmloAQsFhzJQhSn7UWxxFru3AEwNrrmPEsHdjTnjBiXXF89/drO3Hd/oB "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Explanation:
```
ÔºµÔº≠Œ∏‚ü¶‚Ññ‚Ä¶Œ∏Œ∫ŒπŒπ‚üß
```
Replace each value with a tuple of its occurrence index and value.
```
Ôº∑‚ÅªŒ∏œÖ‚äûœÖ‚åäŒπ
```
Sort the tuples into order.
```
Ôº©Ôº•œÖ‚äüŒπ
```
Output the sorted values.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 5 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
{Œ≥Œ∂Àú√æ
```
[Try it online.](https://tio.run/##yy9OTMpM/f@/@tzmc9tOzzm87///aEMdUx0jILTQMQazLGMB)
**Explanation:**
```
{      # Sort the (implicit) input-list
 Œ≥     # Group it into equal adjacent values
  Œ∂    # Zip/transpose; swapping rows/columns,
       # using " " implicitly as filler for unequal length lists
   Àú   # Flatten this list of lists
    √æ  # Remove all " " by only keeping integers
       # (after which the resulting list is output implicitly)
```
[Answer]
**APL(NARS), 23 chars**
```
{0‚â•‚â¢‚çµ:‚ç¨‚ãÑa[‚çãa],‚àá‚çµ‚àº‚ç¶a‚Üê‚à™‚çµ}
```
use:
```
  {0‚â•‚â¢‚çµ:‚ç¨‚ãÑa[‚çãa],‚àá‚çµ‚àº‚ç¶a‚Üê‚à™‚çµ}1 5 2 2 8 3 5 2 9
‚îå9‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îê
‚îÇ 1 2 3 5 8 9 2 5 2‚îÇ
‚îî~‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îò
```
zilde has to be as void set for all the types
[Answer]
# APL+WIN, 30 bytes
Prompts for list of integers:
```
(,‚çâ‚äÉ(‚åà/¬®‚ç¥¬®n)‚Üë¬®n‚Üên‚äÇn‚Üêm[‚çãm‚Üê‚éï])~0
```
[Try it online! Thanks to Dyalog Classic](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qvz6O2CcZcQJanP5BlyPWooz3tv4bOo97OR13NGo96OvQPrXjUu@XQijzNR20TgRRQVd6jriYQnRv9qLc7F8gAao/VrDP4D9TM9T@Ny1DBVMEICC0UjMEsSy4A "APL (Dyalog Classic) ‚Äì Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 62 bytes
```
a=>a.map(t=$=>[t[$]=9+t[$]||Array($)+t,$]).sort().map(x=>x[1])
```
[Try it online!](https://tio.run/##HYpBCoMwFESv4iKLfEwjWgpm8QM9R8jiY7W0WCNJEAvePcYwi3nMmy9tFAb/WeNtca8xTZgINckfrTwiQ22iYRZVfdVxPL2nP2dQR8EsyOB85FDOO@rdtBbS4Jbg5lHO7s0nblrxEF1OL@6FlAWomqbKoitTL1SmrGw6AQ "JavaScript (Node.js) ‚Äì Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 5 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
√º √ïcf
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=/CDVY2Y&input=WzEsNSwyLDIsOCwzLDUsMiw5XQotUQ)
```
√º √ïcf     :Implicit input of array
√º         :Group & sort by value
  √ï       :Transpose
   c      :Flatten after
    f     :  Filtering (to remove null values)
```
[Answer]
# [Haskell](https://www.haskell.org) + [hgl](https://www.gitlab.com/wheatwizard/haskell-golfing-library), 11 bytes
```
cx<tx<sr<bg
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ8FN58zcgvyiEoXC0sSczLTM1BSFgKLUnNKUVC6oBJSroKEJF-FKs7KK9swridW1A1NLS0vSdC3WptkmV9iUVNgUF9kkpUPEbvrlJmbmKdgqpORzKSgUFCmoKKQpRBvqGMUicWNRpXQM0QUsgRhMQm1asABCAwA)
## Alternative
```
cx<tx<gr<sr
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ8FN58zcgvyiEoXC0sSczLTM1BSFgKLUnNKUVC6oBJSroKEJF-FKs7KK9swridW1A1NLS0vSdC3WptkmV9iUVNikF9kUF0HEbvrlJmbmKdgqpORzKSgUFCmoKKQpRBvqGMUicWNRpXQM0QUsgRhMQm1asABCAwA)
## Explanation
* `bg` group the input into bags of equal elements
* `sr` sort the bags by value
* `tx` transpose
* `cx` concat
## Reflection
There are a couple of ways hgl could be improved I'm seeing here:
* There are two options for how to sort the bags in `bg`
	+ Sort by how many items are in a bag
	+ Sort by how early the earliest item appearsNeither of these is really helpful in this case. It might be nice to have a case function to sort by the value in the bags which would save us here, but really we need an option for the user to specify how to sort (wouldn't help here since `sr<bg` is already quite short).
* There's probably an argument to be made to have a combined `cx<tx`. I can see that being used in more places than just here.
[Answer]
# [Python](https://www.python.org), 53 bytes
```
f=lambda L:[*map(L.remove,x:={*L})]and sorted(x)+f(L)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vwYKlpSVpuhY3TdNscxJzk1ISFXysorVyEws0fPSKUnPzy1J1Kqxsq7V8ajVjE_NSFIrzi0pSUzQqNLXTNHw0oZot0_KLFCoUMvMUog11THWMgNBCxxjMsozVibbQMQWSIFGjWCsuhYKizLwSjTSgGZpcEANgrgAA)
Straight-forward method used by many other answers previously:
Pick, sort and remove uniques and start over.
[Answer]
# [Scala 3](https://www.scala-lang.org/), 118 bytes
A Port of [@matteo\_c's Haskell answer](https://codegolf.stackexchange.com/a/268516/110802) in Scala.
---
Golfed version. [Attempt This Online!](https://ato.pxeger.com/run?1=XVFNTwIxEI1XfsW48dCGsokgCWB2E7yZ-HHQeCGE1N2u1CzddTuLEMIv8cJFL_4i_DXOdoGISdP2zby-eZ35-LKRTGXne-S1TPYuC-ONt_3s-VVFCLdSG1ALVCa2MMxzWDUA5jKFZMAe1Nvo2uA4CPc3DgF8lpi0etv5BGYSo-kqklbBnU6DkLZLhxZBuPBtVqCK_Vhb1CbCZjNhh-BLkZX51ZLpWBnUuOT-TOZPMi2VZRMfpU65P3fQT1KJ5M7HjEzwdV3950TXLlFZrEpaMnZDlRi5B2Duei6gK6DtVk9AZw_7XABpVfn2Pkz5voMVhXPxR-ZCQLXo0RE84tDz7p5QqR1lXefYLr0DnNK8QdvhA36SFUpGU1iB6yHTJi9R0GxympOK70skTAMInbK0VhXIkppG4eAfU4D1HkkcEuqmioHkwXEHcOZOr_KwrjzkhTaYGuYN07qjFvJKPz4lzq7jm019_gI)
```
_ match{case Nil=>Nil;case x=>x.sorted.distinct++f(x.sorted.groupBy(identity).mapValues(_.tail).values.flatten.toSeq)}
```
Ungolfed version. [Attempt This Online!](https://ato.pxeger.com/run?1=ZZLNSgMxEMfBY59iXDwkuF2wtaCFChU8CH5cxEspEnezGkmzy2a2tkifxEsvevHg-_g0TrK7dWshkMzML_9kPt4_bSy06H9Ngq7JXkVhgun6o8S0e_Kz9509vsgY4VooA3KB0iQWxnkObx2ARKaQMm1xCFfK4uTS4JS3zjACCsJMYPzsLwDEwkq4URpGZ2778y3I4y2AudBgswJlQgKLqDq2YgnpKxPjhZYzadASVTFRE2nBT0VW5jLZZX3gfMlUQn6FSx7NRH4vdCkte4hQKM2juTejVAukzCPMXGq1-M4vDg-pGP-e4wSvOp3qKygtulzdJ5wQ80rMH49CGITQ8-skhH5jnvIQGqDX-Ak49aZjOA9bOschuNXcaswthq4PGsCpbUV941gdrg2XBXdZbDKI0qyQwnW16h5TJi8xpAnJaVpkclsi2bzpqbBWFsjSCiP36B8Zgg3uSBxSqjv1neTBs0M48HuwqWReKIPasGCsq5JayJ1-sk_MqprbenzX9f4L)
```
object Main extends App {
  def f(lst: List[Int]): List[Int] = lst match {
    case Nil => Nil
    case x =>
      val sorted = x.sorted
      val distinctElements = sorted.distinct
      val groupedElements = sorted.groupBy(identity).mapValues(_.tail).values.flatten.toList
      distinctElements ++ f(groupedElements)
  }
  val testcases = List(
    (List(1, 5, 2, 2, 8, 3, 5, 2, 9), List(1, 2, 3, 5, 8, 9, 2, 5, 2)),
    (List(4, 4, 4), List(4, 4, 4)),
    (List(8, 5), List(5, 8)),
    (List[Int](), List[Int]())
  )
  testcases.foreach { case (input, expectedOutput) =>
    assert(f(input) == expectedOutput, s"Test failed for input: $input")
  }
  println("All tests passed!")
}
```
[Answer]
# [Desmos](https://desmos.com/calculator), 63 bytes
```
f(l)=sort(l,[l[1...i][l=l[i]].countfori=[1...l.count]]2l.max+l)
```
Port of some other answers which sort by running occurrence count and value of the corresponding element.
[Try It On Desmos!](https://www.desmos.com/calculator/ksmat6jvbu)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/bmxtlobv65)
[Answer]
**[Q](https://code.kx.com/q/), 51 Bytes**
```
{$[x~();x;asc[key g],.z.s x asc(,/)_[1]'[g:(=:)x]]}
```
The above function takes an implicit parameter, *x*, and:
* returns *x* if it is empty
* otherwise, groups the items in *x* using K function *=:* which is equivalent to Q function *group*. This yields a dictionary where each key is a unique items in *x* and each value is a list of the indexes at which the item occurs in *x*
* and returns:
1. the sorted, unique items in *x*. The unique items are found by taking the keys of the group dictionary
concatenated with
2. the results of a recursive call to the function (*.z.s*) with the remaining items as the parameter. The remaining items are found by dropping the first index from each list in the group dictionary values (using *\_[1]'*), merging the lists (using *,/*), and grabbing the items at those indices from *x*
]