Simple Bubble sort question

Discussion in 'C++' started by NervousWreck, Sep 6, 2010.

  1. NervousWreck

    NervousWreck New Member

    Joined:
    Sep 6, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I'm kind of embarassed to be asking this since I should be able to figure this out by now, but I'm writing a program to sort a vector of objects alphabetically by a string member variable.

    Can someone help me figure out why the bubble sort below won't work? The whole thing compiles fine but outputs the data unsorted.
    Code:
     for(int y = 0; y < 49; y++){
    for(int x = 0; x < 49; x++){
    tResult= strcmp(deansList[x].lastName.c_str(), deansList[x+1].lastName.c_str());
    if(tResult > 0){
    swapper = deansList[x];
    deansList[x] = deansList[x+1];
    deansList[x+1] = swapper;
    }//if
    }//loop
    }//outer loop
    Thanks a lot.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice