1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Simple Bubble sort question

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

  1. NervousWreck

    NervousWreck New Member

    Sep 6, 2010
    Likes Received:
    Trophy Points:

    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.
     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;
    }//outer loop
    Thanks a lot.

Share This Page