The need for the in-place swap is nowadays very limited. The first reason is that present compilers can optimize swap code using temporal variable in many ways, which can be even more effective than in-place swap – thus its usage is superfluous and might even confuse the compiler (and result in an inefficient machine code). Secondly the processors can manage the common approach with the helper variable in a more effective way. The third reason why not to use the in-place swap is that it can be only used to swap variables, whose content has the same length. Last but not least – the algorithm has a very low readability, which can result in a lower maintainability of the code.
Read full article from In-place swap - Algoritmy.net
No comments:
Post a Comment