C++ Notes: Example - push

This function adds a new value to the end of the values in an array.

void push(int a[], int& n, int maxsize, int val) {
   // function:
   //    Reads from cin until array full or to an EOF.
   // parameters:
   //    a       out    array of values.
   //    n       inout  number of values in a, a[0]..a[n-1]
   //    maxsize in     maximum number of elements that can fit in a.
   //    val     in     new value to put in a[n].
   // returns: 
   //   nothing
   if (n >= maxsize) {
      ;// ERROR - return special value, halt, throw exception, or expand array.
   a[n] = val;