Better HN
topnewbestaskshowjobs
Log inSign up

orhano

1 karma · joined May 12, 2019 (7y ago) · 1 submissions

Submissions

comment 2y ago · link · parent

Not to compete with your brilliant code on optimization, bu I have also written a swap routine that excels especially on numbers close to each other. I know sign function result can be put into a variable, but computers nowadays are so fast...

Anyone feel free to use it.

static void swap(ref int a, ref int b) { int c = (b - a) ; while (c != 0) { a += Math.Sign(c); b -= Math.Sign(c); c -= Math.Sign(c); } }