Skip to main content
some test cases
Source Link
640KB
  • 11.9k
  • 2
  • 35
  • 57

Test cases:

[1, 2][1, 2]

enter image description here

[0, 0, -1][-1, 0, 0]

enter image description here

[-1, -2, 3, -4, -5][-1, 3, -5, -4, -4]

enter image description here

[3, 2, 2, 2, 1, 2][3, 1, 2, 2, 2, 2]

enter image description here

Test cases:

[1, 2][1, 2]

enter image description here

[0, 0, -1][-1, 0, 0]

enter image description here

[-1, -2, 3, -4, -5][-1, 3, -5, -4, -4]

enter image description here

[3, 2, 2, 2, 1, 2][3, 1, 2, 2, 2, 2]

enter image description here

Source Link
640KB
  • 11.9k
  • 2
  • 35
  • 57

x86-16 machine code, 25 bytes

00000000: e316 8bd7 03d1 4afc aca8 0174 03aa eb06  ......J....t....
00000010: 87d7 fdaa 87d7 e2ef c3                   .........

Listing

E3 16       JCXZ EXIT           ; handle empty input list
8B D7       MOV  DX, DI         ; DI = output list head 
03 D1       ADD  DX, CX         ; DX = output list tail (1 past)
4A          DEC  DX             ; DX = output list tail
        INLOOP: 
FC          CLD                 ; string direction forward 
AC          LODSB               ; get next char 
A8 01       TEST AL, 1          ; is even? NZ if odd, ZF if even 
74 03       JZ   EVEN 
        ODD: 
AA          STOSB               ; write to list head 
EB 06       JMP  DONE 
        EVEN: 
87 D7       XCHG DX, DI         ; DI = list tail 
FD          STD                 ; string direction reverse 
AA          STOSB               ; write to list tail 
87 D7       XCHG DX, DI         ; DI = list head 
        DONE:
E2 EF       LOOP INLOOP         ; continue looping input list
        EXIT:
C3          RET                 ; return to caller

Callable function, input list at DS:SI, length in CX. Output list buffer at ES:DI.

If input number is odd, is added to the beginning of output list. If even, is added to the end of the output list.