Bubble Sort with Character Arrays in C++

I'm trying to sort a some character arrays in alphabetical order with a bubble sort function. But my if statement doesn't seem to be right. The function loops infinitely and the if statement always executes. I threw in an else statement to print something and it never came up so the if statement seems to always be executing for some reason.

If you need to see anymore of the code to help me out just let me know, but I'm pretty sure the problem is in this function somewhere.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
while (swap)
{
   swap = false;
   for (int i = 0; i < count; i++)
   {
       if (items[i].name < items[i + 1].name)
       {
               strcpy(items[i].temp, items[i].name);
               strcpy(items[i].name, items[i + 1].name);
               strcpy(items[i + 1].name, items[i].temp);
               temp1 = items[i].quantity;
               items[i].quantity = items[i + 1].quantity;
               items[i + 1].quantity = temp1;
               temp2 = items[i].price;
               items[i].price = items[i + 1].price;
               items[i + 1].price = temp2;

               swap = true;
        }

   };

};
It all depends on what type name is and, more importantly, what the behavior of the < operator is on that type. I'm guessing it's not comparing them in the way you think/want.
Topic archived. No new replies allowed.