
_________ skip whitespace
	cin.unsetf(ios::skipws);		// unset skip whitespace
	getchar()  ??????
	
	cin.setf(ios :: ???)
	skipws  internal  hex  uppercase  scientific 
	left dec showpoint showpos showbase right oct fixed
	
_________ abs
include <stdlib.h>
abs(mInt);       // convert to absolute value
_____
#include <cmath>
sqrt(value)
pow(x, y)  // x to the y

_________ PI and MAXINT
#include <values.h>
M_PI		// pi
MAXINT      // max integer
	
_________ printing with table
	cout << setw(16) << "Circumference: " 
	     << (2 * M_PI * planetRadius) 
	     << " meters" << endl;
	     
_________  file in ASCII
	#include <fstream>
	ifstream inStream (pFileName);	
	inStream.open(pFileName);				// open file
	inStream.unsetf(ios::skipws);			// unset skip whitespace	
		while (! inStream.eof() ) {
			inStream >> c;						// read file
			
			// new word if space or EOF
			if ( isspace(c) || inStream.eof() ) {
				wordCount[wordLength]++;	// inc wordcount array
				wordLength = 0;					// reset wordLength
			} else if ( isalpha(c) ) {			
				wordLength++;					// count regular characters
			}
		}
		inStream.close();						// close pFileName

_________  file in BINARY

	ifstream  inStream;
	inStream.open(fileName, ios::binary | ios::in );
	
	int mInt, num_compares = 0;
	node<int> * placeNode = mList.first();
	
	// ensure file exists
	if (inStream == NULL) {					// file not found
		cout << inStream << " -- Input file not found!\n";
	} else {									// file OK
		while (! inStream.eof() ) {				// read file	
			inStream.read((char*) &mInt, sizeof(int));
			mList.insert(placeNode, mInt);
		}
		inStream.close();
	}

_____ or...
inStream.open(inFile, ios::binary | ios::in );
inStream.read( (char*) &tag, sizeof(int) );
// read table in from file
inStream.read( (char*) &table, TOTLETTERS * sizeof(int) );
inStream.close();

_____ file out ASCI
	ofstream outFile;
	outFile.open(fileName);
	
	for (int binNum = 0; binNum < LETTER_AZ; binNum++) {
		int counter = 0;
		while(letterLists[binNum][counter]) {
			outFile << letterLists[binNum][counter] << endl;
			counter++;
		}
	}
	outFile.close();
____ file rewind
	inStream.seekg(0);							// rewind infile
	inStream.clear();							// clear eof
	
____ file out BINARY
	// declare out file as binary
	outStream.open(outFile, ios::out | ios::binary );
	
	// ensure file exists
	if ( ! outStream) {							// check for error
	
		cerr << "Can't write file " << outFile << "." << endl;
		outStream.close();
		exit (1);								// end.
	}
	
	// save huffpuff tag
	int tag = TAGNAME;
	outStream.write( (const char*) &tag, sizeof(int) );
	
	// save out table header
	outStream.write( (const char*) &table, TOTLETTERS * sizeof(int) );
	
	outStream.close();

____ OVERLOADING, enum day, month, year
enum DayType    {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
enum MonthType  {January, Febuary, March, April, May, June,
                 July, August, September, October, November, December};
enum SeasonType {Fall, Winter, Spring, Summer};

DayType operator+ (DayType d, int increment)
{
	d = (DayType) ( (int) d + increment );
	
	while ( (int) d >= DAYSINWEEK) {
		d = (DayType) ( (int) d - DAYSINWEEK );
	}
	
	return d;
}

______ typedef
const int YRSFROM89 = 10;
const int MONTHS    = 12;
typedef double monthlyRain[MONTHS + 1];
typedef monthlyRain year[YRSFROM89 + 1];
_____
strcpy(s1, s2);   // s1 = s2
strcmp(s1, s2);	  // returns 0    if s1 == s2
strcat(s1, s2);	  // append s2 to s1

_______ sprintf
#include <cstdio>
	int lastPossDay;
	char vDayStr[80];					// string to hold valid day text
	sprintf(vDayStr, "Type a valid day (between 1 and %d): ", lastPossDay);

_______ isspace(c)
#include <cctype>
isalpha(c)
isspace(c)
isupper(c)
isdigit(c)
c = tolower(c);
c = toupper(c);

________ strcmp
#include <cstring>
if ( strcmp(fileName, "none") == 0)

________ length(s)
int length (char a[])
{
	int i = 0;
	while(a[i])
		i++;
	return i;
}
______ struct
struct studentType
{
	char	name[80];
	int		scores[10];
	bool	ownsComputer;
}

_______ assigning arrays
	char aa[80] = {"hello\n"};
	char bb[]   = {"smelly\n"};
	int i[] = {1, 2, 3, 4, 5, 6, 7};
	
______bitset

bits |= (1 << val);  			// setBit(int& bits, int val)
bits &= ((1 << val) ^ 255);   	// clearBit(int& bits, int val)
return (bits & (1 << val) );	// getBit(int bits, int val)

_____ binary sets

{ 4, 10 }
00001000001   (backwards  last value is 2^0, first is 2^10)
2^10 + 2^4 = 1040
1034 + 16  = 1040

  set_a = {2, 9, 6, 4}    set_b = {3, 6, 2, 8, 7}
  a) set_a + seb_b = { 2, 3, 4, 6, 7, 8, 9 }	// a | b		bitwise OR		union
  b) set_a * set_b = { 2, 6 }					// a & b		bitwise AND		intersection
  c) set_a - set_b = { 9, 4 }					// a & (b ^ 255)				difference
  d) set_b - set_a = { 3, 7, 8 }
  
____ new
components = new int[length];
delete [] components;

_____ recursive backtracking
//
// search_for_coloring - generates solutions to the map-coloring
// problem using recursive backtracking.
//
// This function should returns true if a solution has been found,
// or false if backtracking is needed.
//
bool search_for_coloring(int state_num, int num_states)
{
	for (COLOR color = red; color <= blue; color = (COLOR)((int)color + 1)) {
		if ( legal_color(color, state_num) ) {
			add_color(color, state_num);
			
			if ( state_num == num_states ) {		// base case
				return true;
			} else {
				if ( search_for_coloring(state_num + 1, num_states) ) {
					return true;
				}
			}
			
			// if we make it here, solution failed
			remove_color(color, state_num);
		}
	}

	return false;
}
_____ Tree arry
leftChild  = array[i*2];
rightChild = array[i*2 + 1];

_____ Fibonacci merge

A file of integers contains 44 runs
 After the distribution phase of Fibonacci merge, how many real runs and
   how many dummy runs will be in each file?
   
   ... working ...
   Fib. = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144}
   A: (1) (2) (3) (5) (8) (13) (21) (34)
   B: (1) (1) (2) (3) (5) ( 8) (13) (21)
   
   There will be:
   A: 31 real + 3 dummy = 34 runs total
   B: 13 real + 8 dummy = 21 runs total
   
 How many merging passes?
      distribution
   0F:
   1A: 31 real + 3 dummy
   2B: 13 real + 8 dummy
   
   1st merging pass
   0F: 21 real
   1A: 10 real + 3 dummy
   2B:
   
   ...eight merging passes
  
 _____ SORTING EXAMPLES!!!  Remeber - could be from either end.
 // Insertion sort
 // Selection sort
 // Bubble sort
 // Shell Sort
 // heap Sort
 // quick Sort
 
 ______ template

//  Prints list via
//  incrementing the pointer
void printList(list<int> mList)
{
	node<int> * ptr  = mList.first();
	node<int> * last = mList.last();
	
	while(ptr != last) {
		cout << ptr->data << " ";
		ptr = mList.next_node(ptr);
	}
	cout << endl;
}

// reverse_list -- reverse the list of items
template <class elt>
void list<elt>::reverse_list()
{
	node<elt> * temp;
	
	// get number of items [n] in list 
	int n = get_num_items();

	// append n items to list end, deleting originals
	for(int i = 0; i < n; i++ ) {
		temp = retrieve(n-i);		// get last item
		append(temp->data);			// append item to end of list
		remove(temp);				// delete original item
	}
}
____ make file read only
	// make outFile read only
	char tempStr[MAXSTR];
	sprintf(tempStr, "chmod -w %s", outFile);
	system(tempStr);
	
_____Using sprintf
// sprintf(myString, "%s%c%s", strA, myChar, strB);

_____Using strstr
// if (strstr(line, "<delim")) {
//      cp = strstr(line, "value=");
//      valueChar = cp[6];
// }
_____asci to string
//  readers = atoi(optarg);    atoi()   asci to string
_____Copy constructor
class Class1 { public: int a; int *p; };
Class1:Class1(const Class1 &c)
{
	a = c.a
	p = new int;
	*p = *(c.p);
}
____ fctn to delete all memory from llist
void dlist(item *head)
{
	if (head == NULL) return;  // base
	dlist(head->next);
	delete head;
}
____ fctn to deallocate all memory to tree
void dtree(node *root)
{
	if (root == NULL) return;
	dtree(root->left);
	dtree(root->right);
	delete root;
}
____ mapping
Prim's algorithm - like depth first but a set
Kruskal's algorithm - multiple sets
Djkstra's algorith - all paths, best path from start.

