I cant keep this struct bubble sort to work

I keep getting run time errors when running the following.




Tree temp;
bool swap;
do
{
swap = false;
for(int c=0; c <SIZE; c++)
{
if(data[c].treeID > data[c+1].treeID)
{
temp = data[c];
data[c] = data[c+1];
data[c+1] = temp;
swap = true;
}

}
}
while(swap);

the run time error is as follows:

Unhandled exception at 0x7682c41f in tree.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x003e9c34..
Last edited on
bad_alloc means that you tried to allocate memory and failed. The code you posted doesn't do that.

The problem is likely somewhere in your Tree constructor.

BTW, you don't typically bubblesort a Tree. What are you trying to accomplish here?
I think I figured it out, so don't worry about it
Topic archived. No new replies allowed.