Expand|Select|Wrap|Line Numbers
- short max;
- cout << "\nHeapsort Program\n\n";
- cout << "Enter # of elements to generate: ";
- cin >> max;
- short* unsortedList = new short[max];
- cout << "Generating list of integers...";
- for (short x=0; x<max; x++)
- {
- unsortedList[x] = (rand()%100)+1;
- }
- cout << " done.\n\nInitializing sort...";
- //actual sort code follows, of course
terminate called after throwing an instance of 'std::exception'
what(): St9exception
Initializing sort...Aborted
Bear in mind that printing "Initializing sort..." is actually part of my code. So it throws an exception buts somehow executes the next line anyway. Also, when the number is really high (500,000 for example), it generates this error instead:
terminate called after throwing an instance of 'std::bad_alloc'
what(): St9bad_alloc
Aborted
Note the lack of "Initializing sort..." in this case, meaning it terminated before the next line this time. At first I thought it was just running out of memory, so I changed the ints to shorts (as seen in the code), but it didn't change anything.
Oh, and as a technical point, I'm using Linux GPP, and the use of a pointer is necessary to how the heap works (it's essentially a priority queue).