// From the software distribution accompanying the textbook // "A Practical Introduction to Data Structures and Algorithm Analysis, // Third Edition (C++)" by Clifford A. Shaffer. // Source code Copyright (C) 2007-2011 by Clifford A. Shaffer. // This program tests that swapping can be done by adding and // subtracting the values. This is an alternative to using XOR // to swap without a temporary variable. The thing to be confirmed // is that overflow and underflow won't mess up the results. #include "book.h" int main(int argc, char** argv) { int numtrials = 1000000; // Lets try a million times to break this. int a, b; // The values to be swapped int origa, origb; // Copies to make sure the swap worked. Randomize(); for (int i=0; i