I have a simple plane object with public datamembers of a flight number and a pointer. I am successfully adding "planes" and deleting "planes," however when I try to move one up a spot, though it compiles well, I seem to get memory crashes.
Here is my bump function that passes the lead pointer for my linked list. I put cout statements in the function to see if i could pin point where it was crashing and it seems to be in my while loop. I'm sort of a newb really so im sure im doing something fairly obvious that is incorrect.
void bumpPlane (plane*& pstart)
{
int flight;
cout << " Enter the flight number you would like to move ahead" << endl;
cin >> flight;
plane* ptarget = NULL;
plane* pcurrent;
pcurrent = pstart;
plane* pbefore = NULL;
if(pstart == NULL)
cout << "No planes on the queue" << endl;
while (pcurrent != NULL)
{
if(pcurrent->flightnum == flight)
ptarget = pcurrent;
else
{
pbefore = pcurrent;
pcurrent = pcurrent->pnext;
}
}
if (ptarget = NULL)
{
cout << "Could not find flight number in the queue" << endl;
return;
}
plane* psave = NULL;
psave = pcurrent->pnext;
pcurrent->pnext = pbefore;
pbefore = psave;
}
ps. My first post here, though im a lurker and like to browse around here to pump me up to do my homework.