Insert Sorting Random Numbers

CSC404, Data Structures
Programming Assignment 4
Due February 8, 2001

You are to write a program that will Each of those four instructions are to be done using functions.
 
  1. Test your program to create a file with a variety of values for N, both small and large values.
  2. Use your program to create a file "Assignment4.txt" containing 100 random integers.
  3. E-mail your text file along with your source code to albert@crawfordenterprise.com

Text file input and output:

  1. Open a file for input
    1. #include <fstream.h>
      fstream FileVar;
      FileVar.open(filename, ios::out);
  2. Open a file for output
    1. #include <fstream.h>
      fstream FileVar;
      FileVar.open(filename, ios::in);
  3. Close a file
    1. FileVar.close();
  4. Read from a file
    1. FileVar >> dataValue;
  5. Write to a file
    1. FileVar << value1 << value2;
      FileVar << value1 << value2 << endl;
Insert Sort Code

void InsertSort( ItemType SortArray[], int Size )
{  ItemType Temp;
   int Pass, K;

   for (Pass = 1; Pass < Size; Pass++ )
     { Temp = SortArray[Pass};           // save the item to be inserted
       K := Pass;                        // start comparing with those items already inserted
       while ((K > 0) and (Temp < SortArray[K-1]))  // assending order
         { // proper location not found, move items down and continue
           SortArray[K] = SortArray[K-1];  // move item down in array
           K--;
         }

       SortArray[K] := Temp;  // place current item to be inserted into its proper place
     }  // end current Pass
}  // end InsertSort