Link to home
Start Free TrialLog in
Avatar of microcoop
microcoop

asked on

Bubble Sort on a Char Field

I am trying to use a bubble sort but the field I want to sort on is a Char[16]. I need to sort this based on this column char column, but as you can see I need to do some sort of comparing. Any suggestions or am I going about this all wrong?

Here is the semi bubble sort

int newpos = 3;
int j;
int k;
bool exchangeMade;
char temp[16];
k = 0;
exchangeMade = true;
        while ((k < newpos - 1) && exchangeMade)
        {      exchangeMade = false;
                ++k;
            for (j = 0; j < newpos - k; ++j)
      {
            if (memsort[j].inventory > memsort[j + 1].inventory)
                      {            
                            temp = memsort[j].inventory;
                  memsort[j].inventory = memsort[j + 1].inventory;
                  memsort[j + 1].inventory = temp;
                             exchangeMade = true;
                       }
      }
        }
ASKER CERTIFIED SOLUTION
Avatar of efn
efn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial