// From the software distribution accompanying the textbook // "A Practical Introduction to Data Structures and Algorithm Analysis, // Third Edition" by Clifford A. Shaffer, Prentice Hall, 2007. // Source code Copyright (C) 2006 by Clifford A. Shaffer. // Test out the collatz sequence. #include using namespace std; #include "book.h" int main(int argc, char** argv) { int n; Assert(argc == 2, "Usage: collatz "); // The book version has no print statement. // So, lets run a version with a print statement so that we // can see what is going on. n = atoi(argv[1]); cout << "The start value for the Collatz sequence is: " << n << "\n"; while (n > 1) { if (ODD(n)) n = 3 * n + 1; else n = n / 2; cout << n << " "; } cout << endl; return 0; }