This is my first question, so please give me feedback not only on the question but on how I asked it as well (please and thank you).
In my last assignment for CS 201 we designed a class representing an airline flight, it contains some private data:
string airline, originAirport, destinationAirport;
int flightNumber, departureTime, arrivalTime; //times from 0000 to 2359
Part of the assignment was to display all departures or arrivals (as selected by the user) for a single airport. For extra credit, the output was to be sorted in ascending order (earliest time first). The instructor has not taught us how to use std::sort from so the idea (I assume) was to devise our own method of sorting.
My thinking was to fill an array of Flight pointers according to the results of a sort; however I ran into a problem. Here is my code to do the sorting:
for(i=0; i<maxArraySize; i++)
{
minIndex = i; //assume that element i is the earliest arrival time
for(j=0; j<maxArraySize; j++) // j=i produced unsorted results
{
if (flightArray[j].getArrivalTime() < flightArray[minIndex].getArrivalTime())
minIndex = j;
} // at the end of this loop, I now have the smallest flight time's index
pointerArray[i] = &flightArray[minIndex];
} //when the loop terminates I *should* have a sorted list of pointers (but I don't)
I looked over the output to see what the problem was and I realized that all the pointers were pointing to the same flight (which did, indeed, have the earliest arrival time). This led me to believe that the problem was that my code was not excluding flights which had already been placed into pointerArray.
Outside of "blanking" the flight that I just pointed to (which defeats the purpose of the pointer) I could not find any way of "ignoring" flights which already had pointers pointing at them.
How can I have solved this problem?
I would like to make it clear that I have already solved the problem in a very hack-y way. I am not happy with the solution because I feel it is not optimal but it works. I am not attempting to have SO do my assignment, just help to make me a better programmer