Array/Structure Bubble Sort
I have an array of structures which I am attempting to bubble sort.
My problem is I cannot get a "temp" struct to hold one of the structures within the array for the sort.
My data is valid within the array, but after the sort I am getting junk output.
Is there an "easy" way to do this?
Here's the sort currently:
Code:
/* FYI:
struct key
{
char invnbr[16];
int recnbr;
};
key *keyptr = new key[12];
key tempkey; */
while ((k < rrn - 1) && exchangeMade)
{
exchangeMade = false;
++k;
for (j = 0; j < rrn - k; ++j)
if (keyptr[j].invnbr > keyptr[j + 1].invnbr)
{
tempkey = keyptr[j];
keyptr[j] = keyptr[j + 1];
keyptr[j + 1] = tempkey;
exchangeMade = true;
}
}
I have also tried to pass each member of the struct as well to no avail. (eg: tempkey.member = keyptr[j].member).
I'm seriously confused, any pointers (no pun) appreciated!