[Question]
  [
Rearrange a given list such that all the odd numbers appear before all the even numbers. Besides for this requirement, the output list may be in any order.
The input will only contain integers, but they may be negative and there may be duplicates, and they may appear in any order.
Shortest solution wins.
### Test cases
`[1,2]` → `[1,2]`
`[2,1]` → `[1,2]`
`[1,0,0]` → `[1,0,0]`
`[0,0,-1]` → `[-1,0,0]`
`[3,4,3]` → `[3,3,4]`
`[-4,3,3]` → `[3,3,-4]`
`[2,2,2,3]` → `[3,2,2,2]`
`[3,2,2,2,1,2]` → `[1,3,2,2,2,2]` or `[3,1,2,2,2,2]`
`[-2,-2,-2,-1,-2,-3]` → `[-1,-3,-2,-2,-2,-2,]` or `[-3,-1,-2,-2,-2,-2,]`
`[]` → `[]`
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 2 bytes
```
ΣÉ
```
[Try it online!](https://tio.run/##MzBNTDJM/f//3OLDnf//RxvqGOkY65jomOqY6ZjrWOhYxgIA "05AB1E – Try It Online")
[Answer]
# C++, ~~79~~ ~~76~~ 64 bytes
```
[](auto a,auto b){while(a<--b)*a%2?*++a:(*a^=*b,*b^=*a,*a^=*b);}
```
This function accepts a pair of iterators (which must be random access iterators), and steadily moves them towards each other. When `a` points to an odd number, it is advanced. Otherwise, `a` points to an even number; `b` is decremented, and `iter_swap`'ed with `a`. (We use XOR swap, which saves us having to include `<algorithm>` - or `<utility>` for `std::swap`).
There are unnecessary swaps when `b` points to an even number, but we're golfing, not squeezing efficiency!
## Demo
```
auto f=[](auto a,auto b){while(a<--b)*a%2?*++a:(*a^=*b,*b^=*a,*a^=*b);};
#include <array>
#include <iostream>
int main()
{
    auto a = std::array{ 3,2,2,5,2,1,2 };
    f(a.begin(),a.end());
    for (auto i: a)
        std::cout << i << " ";
    std::cout << std::endl;
}
```
---
## Non-competitive answer
The natural C++ method is `std::partition`, but that comes out at **83** bytes:
```
#include<algorithm>
[](auto a,auto b){std::partition(a,b,[](auto x){return x&1;});}
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), ~~4~~ 3 bytes
-1 byte thanks to isaacg
```
iD2
```
[Try it online!](https://tio.run/##K6gsyfj/P9PF6P//aEMdIx1jHRMdcx1TMMtSx9hEx9AoFgA "Pyth – Try It Online")
crossed out 4 is still regular 4
[Answer]
# [R](https://www.r-project.org/), ~~30~~ 24 bytes
```
(x=scan())[order(!x%%2)]
```
[Try it online!](https://tio.run/##K/r/X6PCtjg5MU9DUzM6vygltUhDsUJV1Ugz9r@hgpGCqYKlgpmCsYKJgjmYbQHmGSoYGvwHAA "R – Try It Online")
*-6 bytes thanks to JayCe*
[Answer]
# [J](http://jsoftware.com/), 5 bytes
```
\:2&|
```
[Try it online!](https://tio.run/##y/r/P83WKsbKSK0GyFIwUjBXMFSwANIWYNqYK03BGMgyAWJTBUuguJmCKQA "J – Try It Online")
`\:` sort descending by
`2&|` mod-2
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 2 bytes
```
ñv
```
[Try it online!](https://tio.run/##Dci5DYBADEXBhp4lvne9Ry2IgJSIANEXNVCYYcI59vPKfJ87c7XAKlYwx8SCcAqVoNEZTPSnkKOCKgrUUEcDze0D "Japt – Try It Online")
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 12 bytes
```
*.sort(*%%2)
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYKvwX0uvOL@oRENLVdVI8781V3FipUKaRrShjpGOsY5JrCZcxFjHVMdcx9AASchIx0THTMcSKPIfAA "Perl 6 – Try It Online")
Some Whatever code that sorts the input by parity, with odd numbers first. You can remove a `%` to get even numbers first instead. Note that 'Whatever' is the name of this sort of anonymous function.
[Answer]
# MATL, 6 bytes
```
tog&)v
```
[Try it on MATL Online](https://matl.io/?code=tog%26%29v&inputs=%5B5%2C2%2C3%2C4%2C19%2C7%2C8%2C1%2C20%5D&version=20.9.1)
Alternately:
```
to_2$S
```
[Try it on MATL Online](https://matl.io/?code=to_2%24S&inputs=%5B5%2C2%2C3%2C4%2C19%2C7%2C8%2C1%2C20%5D&version=20.9.1)
[Answer]
# [Haskell](https://www.haskell.org/), ~~23~~ 22 bytes
```
f odd<>f even
f=filter
```
[Try it online!](https://tio.run/##DY2xDoIwFEV3vuIOjtJI4uAgLpjoSOJiog4VXsuLpcVH4fOtnc5wz80Z9Pwh5xKPU5CIs45a3WhkK2GZUJbwAS54SwJP1FMP9rhcGxzUXlUIgoHtQLLFe4kQ@i4sWTJ5iAOhW0TIR6wkMwePbBIyI4fCosYzGYS@P54MaCVfmNqwiyRp1LlTYxLO7w0sHpVS1e6Vfp1x2s6pvDdt@wc "Haskell – Try It Online") This is equivalent to
```
g x = filter odd x ++ filter even x
```
*-1 byte thanks to [Lynn](https://codegolf.stackexchange.com/users/3852/lynn)*
---
Other approaches:
```
(<>).($odd)<*>($even)$filter
import Data.List;sortOn even
g x=[i|m<-[0,1],i<-x,odd$m+i]
g x=[i|m<-[1,0],i<-x,mod i 2==m]
g x=id=<<filter<$>[odd,even]<*>[x]
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~37~~ 36 bytes
```
lambda a:sorted(a,key=lambda x:~x%2)
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHRqji/qCQ1RSNRJzu10hYqWmFVV6FqpPm/oCgzr0QhTSNa11DHRMdYR9dYx0hH1yhW8z8A "Python 2 – Try It Online")
1 byte tip o' the hat to [Mr. Xcoder](https://codegolf.stackexchange.com/users/59487/mr-xcoder).
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 5 bytes
```
{|eom
```
[Run and debug it](https://staxlang.xyz/#c=%7B%7Ceom&i=[1,2,3,4,5,6]%0A[3,57,26,36823435,0]&a=1&m=2)
Explanation:
```
{|eom Full program, implicit input
{  o  Sort by key:
 |e     Is odd?
    m Map over result:
        Implicit output with newline
```
[Answer]
# [Attache](https://github.com/ConorOBrien-Foxx/Attache), 11 bytes
```
SortBy!Even
```
[Try it online!](https://tio.run/##SywpSUzOSP2fpmBl@z84v6jEqVLRtSw1779fampKcbRKQUFyeixXQFFmXklIanGJc2JxanF0mo5CNJcCEEQb6igY6SgY6yiY6CiYxupABC3BIhY6CoYGQGwI5hkbgrhAvhFMlS5Ery5QpzFMLJYrNvY/AA "Attache – Try It Online")
## Explanation
`Even` returns `true` for even numbers and `false` otherwise. `SortBy` ranks `false < true` (by a numerical cast to `0 < 1`), thus placing odd numbers before even ones.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 29 bytes
```
a=>a.sort((a,b)=>(b&1)-(a&1))
```
[Try it online!](https://tio.run/##DcpBCoAgEADA38QKu0LZLfQj0WEtjULc0Oj75mVOc/PHdS/X81KWI7RoG1vHukp5ARi9sg78MCoC7qq27JKrpKCTnBBhpRFnNEgGJ6Rp6@MH "JavaScript (Node.js) – Try It Online") Save 4 bytes by only supporting positive values using `b%2-a%2`. If you write this as:
```
function(a){return a.sort((a,b)=>(b&1)-(a&1))}
```
then it will work on all sorts of old JavaScript implementations that didn't sort stably.
[Answer]
# T-SQL, 26 bytes
```
SELECT*FROM t ORDER BY~i&1
```
Uses the bitwise AND operator "&" to compare the last digit with 1.
EDIT: Bitwise NOT then shorter than adding 1.
EDIT2: Reorder to allow removal of the space.
[Answer]
# [PHP](https://php.net/), 55 bytes
~14 months later and I'm a little bit better at golfing now:
```
for(;''<$n=$argv[++$i];$s=$n%2?"$n $s":"$s $n");echo$s;
```
[Try it online!](https://tio.run/##DcTRCkAwAAXQX9G6QksxtbDJh8iDhHnZlpXfv5yHE12kneP/GZ7SFIWFn7A917tIiXs1SBN8rmYBnyGJUSBl8KIyx@4CkiGp2LBl3bJjTzWw1lp/ "PHP – Try It Online")
---
# [PHP](https://php.net/) (>=5.4), ~~84~~ 82 bytes
(-2 bytes, thanks to [Ismael Miguel](https://codegolf.stackexchange.com/users/14732/ismael-miguel))
```
<?array_shift($a=&$argv);usort($a,function($i){return$i%2==0;});echo join(' ',$a);
```
To run it:
```
php -n <filename> <number_1> <number_2> ... <number_n>
```
Example:
```
php -n sort_odds_first.php 2 0 1 -1 3 8 29 -666
```
Or [Try it online!](https://tio.run/##FczRCsIgGAbQV9mFNYUJm4EUTnqUkLGlXaj8ajCiV@@L3Z6Lk30G5rsjcvuj@LBVzpw9M0fPtzCtJDpg2FpcakiRsyA@tNZGkYWTsnY0X2HWxafulULkfdcPzAkDQGHEBDnhgivUDVJr/Uv5WApk/AM "PHP – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 3 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
ḂÞṚ
```
**[Try it online!](https://tio.run/##y0rNyan8///hjqbD8x7unPX//38LHSMdYx0DHV0THV1DHTMgNAQA "Jelly – Try It Online")**
One of the more oft-wanted atoms seems to be an is-even one (which would make this 2 bytes), without it we must reverse I believe...
```
ḂÞṚ - Link: list of integers
 Þ  - sort by:
Ḃ   -   bit (least significant bit - i.e. 1 if odd 0 if even)
  Ṛ - reverse
```
[Answer]
**JavaScript, ~~22~~ 20 bytes**
`a=>a.sort(a=>!(a%2))`
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/R1i5Rrzi/qEQDyFLUSFQ10tT8b52cn1ecn5Oql5OfrpGmEW2oY6RjrGOiY6pjpqNrqKNrpKNrrKNrEgtUCgA)
[Answer]
# [Python](https://docs.python.org/2/), 35 bytes
```
lambda l:sorted(l,key=(-1).__pow__)
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHHqji/qCQ1RSNHJzu10lZD11BTLz6@IL88Pl7zf46CrUK0rqGOiY6xjq6xjpGOrlEsV0FRZl6JQppGjuZ/AA "Python 2 – Try It Online")
Sorts by the function `x -> (-1)**x`, which gives `-1` for odd and `1` for even.
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), 50 bytes
```
A+S:-predsort([X,Y,Z]>>(Y/\1>Z/\1,X= <;X= >),A,S).
```
[Try it online!](https://tio.run/##FcpLCoAgAEXRrTg0fBZGEvQRXIOTvrMigkgxoeWbTQ5cuM7byx78ec8YNTMNd37fHusDnQeMmFal6FgsQk0JDD3p2oTKoGGyPDaczAIlJJIVZAXxR52yhlyZAXH@vAP95w8 "Prolog (SWI) – Try It Online")
-8 thanks to Jo King
[Answer]
# [Red](http://www.red-lang.org), 42 bytes
```
func[a][sort/compare a func[n][n % 2 = 1]]
```
[Try it online!](https://tio.run/##HcixCoAgFEbhvaf4l@bwqhRBL9F6uYOUQkMqZs9v2HCG7xR/tt2fLENYW3jjwU74SaVOR7qzKx4O/47CESMIG5RIy@WKFQGsoAikYXqaDKwm2A5L0FgwS/sA "Red – Try It Online")
If we need to account for negative values:
# [Red](http://www.red-lang.org), 43 bytes
```
func[a][sort/compare a func[n][n // 2 = 1]]
```
[Try it online!](https://tio.run/##HchBCoAgEEbhfaf4LxDiqBRBl2g7zEJKoUUWVuefsMVbfK@mTZe0sXR50vyWlaPwfdbHrOdxxZoQ8e8iXGAMCDOsiF51Lw8y2MISyMG3HHkER@hDUyA4jBhEPw "Red – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), 4 bytes
```
↔Ö%2
```
[Try it online!](https://tio.run/##yygtzv7//1HblMPTVI3@//8fbaljoWOuY6ZjqGOkY6xjomMaCwA "Husk – Try It Online")
**Explanation**
```
 Ö     sort input according to the result of the following function
  %2   modulo 2
↔      reverse result to get odd numbers to the front
```
[Answer]
# [Scala](http://scala-lang.org), 18 bytes
```
_.sortBy(_.+(1)%2)
```
[Answer]
# C#, 23 bytes
```
i=>i.OrderBy(u=>u%2==0)
```
Quite straigt forward really: This basically converts the numbers to booleans, whilst `true` means that the number is even and `false` that it's odd. Because `true` is higher than `false` the even numbers appear first.
The formatted version looks like that:
```
i => i.OrderBy (u => u % 2 == 0)
```
And you can test it like that:
```
Console.WriteLine (string.Join (",", new Func <IEnumerable <int>, IEnumerable <int>> (
                                    i => i.OrderBy (u => u % 2 == 0)
                                ).Invoke (new [] {3, 2, 2, 2, 1, 2, 5, 5})));
```
Which results in the following:
```
3,1,5,5,2,2,2,2
```
[Answer]
# JavaScript, 23 bytes
6 bytes shorter than [@Neil's answer](https://codegolf.stackexchange.com/a/168782/81748) using the same language :D
```
a=>a.sort(n=>-(n&1)||1)
```
**Explanation:**
The function passed to `sort` only cares about the first parameter. If it is odd it returns `-1` (the result of `-(n&1)`). Otherwise (when `-(n&1)` yields `0`) it returns `1`.
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9Wmpds@z/R1i5Rrzi/qEQjz9ZOVyNPzVCzpsZQ8791cn5ecX5Oql5OfroGSKlGtKGOgomOgq6xjoKpjoIRkAXimYGZEDFzIB@ELXQULHUUDHQUDEHYEEQbxGpq/gcA)
[Answer]
# JavaScript (Chrome v67) - ~~24~~ ~~19~~ 23 bytes
```
a=>a.sort(a=>!(a&1)-.5)
```
The use of `&1` rather than `Math.abs()%2` was stolen from @Neil. Thanks!
Thanks to @Shaggy for showing my hacky 19 byte solution wasn't valid. If anyone wants it:
 ~~Depends on how the browser handles a hacky return value of `0`. Chrome v67, after 100000 iterations of random arrays never sorted it wrong. I'm very sure it works -- and it relies on the specific sort algorithm Chrome uses too, I believe. (It might work in other browsers, that's not the point)~~
`a=>a.sort(a=>++a&1)`
[Answer]
# JavaScript, 21 bytes
```
a=>a.sort(n=>(-1)**n)
```
[Try it online](https://tio.run/##LUxbDoMwDPvnJC1yK0J5fsBFGBIVgwnEWgRo12ctoESx48Se9U/v/TathzD2PZxjdeqq1nK328FMVTNBPAwNP3trdrsMcrEf1gQNIW4RNDHIAyFC5IkDiEtSSKA8EQ5vFsOXuq/38sSIGE/TNW9jCucV6tEj/wwfmyJDjgIlyIkEcjkKlIBSUAbKQQWobINWfvXKRi5nO5nuZTp@/gE)
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), ~~22~~ 19 bytes
```
$args|sort{!($_%2)}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/XyWxKL24pji/qKRaUUMlXtVIs/b///@6RlBk8F/XEMw0/m/y3xQA "PowerShell – Try It Online")
Takes input via splatting, e.g., `$a=(3,4,3); .\sort-odd-numbers-first.ps1 @a`, which on TIO manifests as separate arguments for each entry.
Like some other answers here, `Sort-Object` can compare based on an expression. Here the expression is `!($_%2)`, i.e., odds get sorted to `$false` and evens get sorted to `$true`. Thanks to how Boolean values are compared, falsey values are sorted first. This moves the odds to the beginning of the output, and the evens to the end. `Sort-Object` is stable, so the ordering of the individual items in their respective categories doesn't change (as in the TIO example).
*-3 bytes thanks to mazzy.*
[Answer]
# [Ruby](https://www.ruby-lang.org/), 23 bytes
```
->a{a.sort_by{|i|~i%2}}
```
[Try it online!](https://tio.run/##LcjLCkBAFADQva@4jSzdsKP4EaQr1JRX81hM4/r1QVmdOsqOLix1SBvyhPpQZhidv@R1y6RgDgQ15Bkauc0aNzrBK9onSEvEkqPTGg1C7q8VQGdiTyz@VbO269vfLi31LMID "Ruby – Try It Online")
Explanation:
`sort_by` sorts every number as if its value were the result of the block (`~i%2`)
`~x` is equivalent to `-x-1` and takes precedence over `%2`
Odd numbers will evaluate to `0` and even numbers will evaluate to `1` so odd numbers will be sorted first.
### Barely related: this works on ruby from homebrew 2.5.1p57 (because it's based on a small bug) but only for non-negative integers, 20 bytes
```
->a{a.sort{|i|i%-2}}
```
Explanation:
This uses `sort` which expects a block that takes 2 values and returns `-1`, `0` or `1` depending on whether the first one is bigger, they're equal or the second one is bigger.
The block given here ignores the second value and returns `-1` if the first number is odd or `0` if it's even.
It's not guaranteed to work but it does in some (I think buggy) implementations.
[Answer]
# [6502 machine code](https://en.wikibooks.org/wiki/6502_Assembly) routine, 47 bytes
```
A0 00 84 FE B1 FB 4A 90 07 C8 C4 FD F0 20 D0 F4 2A 85 02 84 FE A4 FD 88 C4 FE
F0 12 B1 FB 4A 90 F6 2A AA A5 02 91 FB A4 FE 8A 91 FB 90 D6 60
```
Expects a pointer to an array of numbers in `$fb`/`$fc` and the length of this array in `$fd`. Manipulates the array in place to have all odd numbers in front. This is position independent code, so no load address is needed.
As the 6502 is an 8bit chip (so the instructions only deal with 8bit values, optionally signed), the valid number range is `[-128 .. 127]` and the maximum array size is `256`.
### Commented disassembly
```
; function to "partially sort" array, so all odd numbers come before all
; even numbers.
;
; input:
;   $fb/$fc: address of array to sort
;   $fd:     length of array to sort, 0 means 256 (maximum size)
;
; clobbers:
;   $fd/$fe: position from back/front of array
;   $2:      temporary for exchanging two values
;   A, X, Y
 .oddfirst:
A0 00       LDY #$00            ; initialize index from front
84 FE       STY $FE             ; to 0
 .search_front:
B1 FB       LDA ($FB),Y         ; load number from front
4A          LSR A               ; check for even/odd by shifting
90 07       BCC .search_back    ; if odd -> to searching from back
C8          INY                 ; next position from front
C4 FD       CPY $FD             ; same as position searching from back?
F0 20       BEQ .done           ; then we're finished
D0 F4       BNE .search_front   ; else check next from front
 .search_back:
2A          ROL A               ; shift carry back in
85 02       STA $02             ; and save number to temp
84 FE       STY $FE             ; save index from front
A4 FD       LDY $FD             ; load index from back
 .sb_loop:
88          DEY                 ; previous position from back
C4 FE       CPY $FE             ; same as position searching from front?
F0 12       BEQ .done           ; then we're finished
B1 FB       LDA ($FB),Y         ; load number from back
4A          LSR A               ; check for even/odd by shifting
90 F6       BCC .sb_loop        ; if odd -> check previous position
2A          ROL A               ; shift carry back in
AA          TAX                 ; remember in X
A5 02       LDA $02             ; load temporary from front
91 FB       STA ($FB),Y         ; store at current position
A4 FE       LDY $FE             ; load index from front
8A          TXA                 ; load remembered number
91 FB       STA ($FB),Y         ; store at current position
90 D6       BCC .search_front   ; and back to searching from front
 .done:
60          RTS
```
---
### Example C64 assembler program using the routine:
**[Online demo](https://vice.janicek.co/c64/#%7B%22controlPort2%22:%22joystick%22,%22primaryControlPort%22:2,%22keys%22:%7B%22SPACE%22:%22%22,%22RETURN%22:%22%22,%22F1%22:%22%22,%22F3%22:%22%22,%22F5%22:%22%22,%22F7%22:%22%22%7D,%22files%22:%7B%22oddfirst.prg%22:%22data:;base64,AQgLCOIHnjIwNjEAAACpF40Y0KkAhSqFUqnnoAkgHqup5KAJIB6rqU+gCqIFIHsIrU8K8B+pT6AKIAgJkAmpLaAKIB6rsNmi/4ZSpiqdVwrmKtDMpVLwI6lXhfupCoX8pSqF/SC1CakAhVKkUrlXCiDuCOZSpVLFKtDwYMqG+4X8hP2gAITMhP4gQvHw+4UCKX/JILAOyQ3wEMkU0Oul/vDn0Aal/sX78N94pNOx0Sl/kdGlAiAW56bP8Aqk07HRCYCR0aUCWMkU8CDJDfAJpP6R/MiE/tCxqQCk/pH8eKTTsdEpf5HR5sxYYMb+sJoQDUn/hQLmAqktIBbnpQKqqQAgzb2pIEwW54X7hPygAIT9hP6MVAqMVQqMVgqx+/AjyMkg8PfJLfAMyTCQFMk6sBDm/ZDnpf3QCKX+0ATm/tDbOGCIMPuiArH7yTCQC8k6sAc46TCdVArKiBDsqQCF+6IITlQKrVUKkAIJEEqNVQqtVgqQAgkQSo1WCmb7yvAmrVQKyQgwBekDjVQKrVUKyQgwBekDjVUKrVYKyQgww+kDjVYKsLyl/vAIqf9F+4X75vul+xhgoACE/rH7SpAHyMT98CDQ9CqFAoT+pP2IxP7wErH7SpD2KqqlApH7pP6KkfuQ1mA+IAANDcVOVEVSIE9ORSBOVU1CRVIgUEVSIExJTkUuDUpVU1QgUFJFU1MgRU5URVIgKEVNUFRZIExJTkUpIFdIRU4gRE9ORS4AxVJST1IgUEFSU0lORyBOVU1CRVIsIFRSWSBBR0FJTi4NAA==%22%7D,%22vice%22:%7B%22-autostart%22:%22oddfirst.prg%22%7D%7D)**
[![screenshot](https://i.stack.imgur.com/wDVrX.png)](https://i.stack.imgur.com/wDVrX.png)
**Code in [ca65](http://cc65.github.io/doc/ca65.html) syntax:**
```
.import oddfirst ; link with routine above
.segment "BHDR" ; BASIC header
                .word   $0801           ; load address
                .word   $080b           ; pointer next BASIC line
                .word   2018            ; line number
                .byte   $9e             ; BASIC token "SYS"
                .byte   "2061",$0,$0,$0 ; 2061 ($080d) and terminating 0 bytes
.bss
linebuf:        .res    5               ; maximum length of a valid signed
                                        ; 8-bit number input
convbuf:        .res    3               ; 3 BCD digits for signed 8-bit
                                        ; number conversion
numbers:        .res    $100            ; maximum array size that can be
                                        ; directly handled with indexing
                                        ; instructions
.data
prompt:         .byte   "> ", $0
message:        .byte   $d, $d, "Enter one number per line.", $d
                .byte   "just press enter (empty line) when done.", $0
errmsg:         .byte   "Error parsing number, try again.", $d, $0
.code
                lda     #$17            ; set upper/lower mode
                sta     $d018
                lda     #0
                sta     $2a             ; index for number array
                sta     $52             ; flag that at least one number was
                                        ; entered
                lda     #<message       ; display message
                ldy     #>message
                jsr     $ab1e
inputloop:
                lda     #<prompt        ; display prompt
                ldy     #>prompt
                jsr     $ab1e
                lda     #<linebuf       ; read string into buffer
                ldy     #>linebuf
                ldx     #5
                jsr     readline
                lda     linebuf         ; empty line?
                beq     process         ; -> start processing
                lda     #<linebuf       ; convert input to int8
                ldy     #>linebuf
                jsr     toint8
                bcc     numok           ; successful -> store number
                lda     #<errmsg        ; else show error message and repeat
                ldy     #>errmsg
                jsr     $ab1e
                bcs     inputloop
numok:          ldx     #$ff            ; set flag that we have a number
                stx     $52
                ldx     $2a
                sta     numbers,x
                inc     $2a             ; next index
                bne     inputloop       ; if array not full, next input
process:        lda     $52             ; check we have some numbers
                beq     exit            ; otherwise exit program
                lda     #<numbers       ; address of array to $fb/fc
                sta     $fb
                lda     #>numbers
                sta     $fc
                lda     $2a             ; length of array to $fd
                sta     $fd
                jsr     oddfirst        ; call "sorting" function
                lda     #$0             ; index variable for output loop
                sta     $52
outloop:        ldy     $52             ; load current index
                lda     numbers,y       ; load current number
                jsr     printnum        ; -> output
                inc     $52             ; next index
                lda     $52             ; compare with ...
                cmp     $2a             ; ... array size
                bne     outloop         ; not reached yet -> repeat
exit:           rts                     ; done, exit program
; read a line of input from keyboard, terminate it with 0
; expects pointer to input buffer in A/Y, buffer length in X
.proc readline
                dex
                stx     $fb
                sta     $fc
                sty     $fd
                ldy     #$0
                sty     $cc             ; enable cursor blinking
                sty     $fe             ; temporary for loop variable
getkey:         jsr     $f142           ; get character from keyboard
                beq     getkey
                sta     $2              ; save to temporary
                and     #$7f
                cmp     #$20            ; check for control character
                bcs     checkout        ; no -> check buffer size
                cmp     #$d             ; was it enter/return?
                beq     prepout         ; -> normal flow
                cmp     #$14            ; was it backspace/delete?
                bne     getkey          ; if not, get next char
                lda     $fe             ; check current index
                beq     getkey          ; zero -> backspace not possible
                bne     prepout         ; skip checking buffer size for bs
checkout:       lda     $fe             ; buffer index
                cmp     $fb             ; check against buffer size
                beq     getkey          ; if it would overflow, loop again
prepout:        sei                     ; no interrupts
                ldy     $d3             ; get current screen column
                lda     ($d1),y         ; and clear 
                and     #$7f            ;   cursor in
                sta     ($d1),y         ;   current row
output:         lda     $2              ; load character
                jsr     $e716           ;   and output
                ldx     $cf             ; check cursor phase
                beq     store           ; invisible -> to store
                ldy     $d3             ; get current screen column
                lda     ($d1),y         ; and show
                ora     #$80            ;   cursor in
                sta     ($d1),y         ;   current row
                lda     $2              ; load character
store:          cli                     ; enable interrupts
                cmp     #$14            ; was it backspace/delete?
                beq     backspace       ; to backspace handling code
                cmp     #$d             ; was it enter/return?
                beq     done            ; then we're done.
                ldy     $fe             ; load buffer index
                sta     ($fc),y         ; store character in buffer
                iny                     ; advance buffer index
                sty     $fe
                bne     getkey          ; not zero -> ok
done:           lda     #$0             ; terminate string in buffer with zero
                ldy     $fe             ; get buffer index
                sta     ($fc),y         ; store terminator in buffer
                sei                     ; no interrupts
                ldy     $d3             ; get current screen column
                lda     ($d1),y         ; and clear 
                and     #$7f            ;   cursor in
                sta     ($d1),y         ;   current row
                inc     $cc             ; disable cursor blinking
                cli                     ; enable interrupts
                rts                     ; return
backspace:      dec     $fe             ; decrement buffer index
                bcs     getkey          ; and get next key
.endproc
; print an int8 number to the screen
; input:
;   A - the number to print
; clobbers:
;   X, Y
.proc printnum
                bpl     doprint         ; positive? -> direct number output
                eor     #$ff            ; else invert, 
                sta     $2              ; ...
                inc     $2              ; add one,
                lda     #'-'            ; output a minus sign
                jsr     $e716
                lda     $2
doprint:        tax                     ; number to X reg
                lda     #$0             ; set A to 0
                jsr     $bdcd           ; routine for uint16 in X/A output
                lda     #' '            
                jmp     $e716           ; and print a space
.endproc
; parse / convert int8 number using a BCD representation and double-dabble,
; handle negative numbers.
.proc toint8
                sta     $fb
                sty     $fc
                ldy     #$0
                sty     $fd
                sty     $fe
                sty     convbuf
                sty     convbuf+1
                sty     convbuf+2
scanloop:       lda     ($fb),y
                beq     copy
                iny
                cmp     #$20
                beq     scanloop
                cmp     #$2d
                beq     minus
                cmp     #$30
                bcc     error
                cmp     #$3a
                bcs     error
                inc     $fd
                bcc     scanloop
minus:          lda     $fd
                bne     error
                lda     $fe
                bne     error
                inc     $fe
                bne     scanloop
error:          sec
                rts
copy:           dey
                bmi     error
                ldx     #$2
copyloop:       lda     ($fb),y
                cmp     #$30
                bcc     copynext
                cmp     #$3a
                bcs     copynext
                sec
                sbc     #$30
                sta     convbuf,x
                dex
copynext:       dey
                bpl     copyloop
                lda     #$0
                sta     $fb
                ldx     #$8
loop:           lsr     convbuf
                lda     convbuf+1
                bcc     skipbit1
                ora     #$10
skipbit1:       lsr     a
                sta     convbuf+1
                lda     convbuf+2
                bcc     skipbit2
                ora     #$10
skipbit2:       lsr     a
                sta     convbuf+2
                ror     $fb
                dex
                beq     done
                lda     convbuf
                cmp     #$8
                bmi     nosub1
                sbc     #$3
                sta     convbuf
nosub1:         lda     convbuf+1
                cmp     #$8
                bmi     nosub2
                sbc     #$3
                sta     convbuf+1
nosub2:         lda     convbuf+2
                cmp     #$8
                bmi     loop
                sbc     #$3
                sta     convbuf+2
                bcs     loop
done:           lda     $fe
                beq     positive
                lda     #$ff
                eor     $fb
                sta     $fb
                inc     $fb
positive:       lda     $fb
                clc
                rts
.endproc
```
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 9 bytes
-7 thanks to @rak1507.
```
{⍵[⍒2|⍵]}
```
Explanation:
```
{⍵[⍒2|⍵]}
    2|⍵      ⍝ ⍵ mod 2, return 1 for each odd element and 0 for each even element
   ⍒         ⍝ pick the indices that produce the array sorted in descending order
  [    ]     ⍝ pick elements corresponding to indices in provided order...
 ⍵           ⍝ from ⍵
```
For example:
```
2|6 7 8 9        => 0 1 0 1
⍒0 1 0 1         => 2 4 1 3
6 7 8 9[2 4 1 3] => 7 9 6 8
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/P@1R24TqR71box/1TjKqATJia/8/6psKFE1TMFQwUjBWMOGC8Q@tNwHyjf8DAA "APL (Dyalog Extended) – Try It Online")
]