:invert
cmp rax, 0
jnz swap:
ret
:swap
push rax
mov rax, [rax]
call invert
mov rbx,[rsp]
xchg rax, [rbx+8]
mov [rbx], rax
call invert
pop rax
ret
The last time I used an assembler was before x86-64 was invented, I am not even sure I ever used one in protected mode. But that seems a totally reasonable whiteboard interview question. Written in notepad, might not assemble. Might even be totally incorrect and I am posting it so that the internet generates the warning and error messages.EDIT: After reading the article now, that seems rather inefficient to me, to use local variables on the stack for everything. And why is the function returning a node if it is mutating the tree in place?