0

Hey everybody,

I am still pretty new to programming. I am not getting a compiler error here, but I can't figure out what the problem is. I get the message

"an unhandled win32 exception occured [1576]"

It seems like some type of overflow in the insertion_sort function. I am still trying to figure it out, but if anyone sees the problem, please let me know.

```
#include "utility.h"
void insertion_sort(short array1[10][10000], int size);
int main()
{
const short column = 10;
const short row = 10000;
const string fileName = "Lab9a.txt";
int matrix_size = column*row;
//vector< vector<short> > matrix;
//short matrix[10][10000];
short (*matrix) [row]= new short [column][row];
// Open the data file
ifstream fin(fileName.c_str());
if (!fin.is_open())
{
cout << endl << "Unable to open input file " << fileName << endl;
return 1;
}// End if (!fin.is_open())
// Fill up matrix
//int temp = 0; //was being used for vector
for(int t = 0; t < column ; t++)
{
for(int i = 0; i < row; i++)
{
fin >> matrix[t][i];
}// End for(int i = 0; i < r; i++)
}// End for(int t = 0; t < s ; t++)
//insertion_sort(matrix);
cout << matrix[9][9999] << endl;
insertion_sort(matrix, matrix_size); // Very slow. Error at end
cout << matrix[0][0] << endl;
cout << matrix[0][1] << endl;
cout << matrix[0][2] << endl;
cout << matrix[0][3] << endl;
cout << matrix[0][4] << endl;
}
void insertion_sort(short array1[10][10000], int size)
/*
Post: The entries of the Sortable_list have been rearranged so that
the keys in all the entries are sorted into nondecreasing order.
*/
{
int first_unsorted; // position of first unsorted entry
int position; // searches sorted part of list
short current; // holds the entry temporarily removed from list
int count = size;
for (int column = 0; column < 5; column++)
{
for(first_unsorted = 1; first_unsorted < count; first_unsorted++)
{
if (array1[column][first_unsorted] < array1[column][first_unsorted - 1])
{
position = first_unsorted;
current = array1[column][first_unsorted]; // Pull unsorted entry out of the list.
do
{ // Shift all entries until the proper position is found.
array1[column][position] = array1[column][position - 1];
position--; // position is empty.
} while (position > 0 && array1[column][position - 1] > current);
array1[column][position] = current;
}
}
}
}
```