May 11th, 2014, 11:45 AM
Re: Sorting with selection, insertion, and bubble sort
yes when dealing with numbers but can't be used for non-numbers such as strings. Also if the number is of a floating point type then rounding errors may happen which could mean that the new a and b values aren't exactly the same as the originals.
This is the standard way of swapping two values. There's actually a template to this in the STL. See http://www.cplusplus.com/reference/algorithm/swap/
temp = a;
a = b;
b = temp;
All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/
C, C++ Compiler: Microsoft VS2017
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!