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

where to increment vector iterator

Discussion in 'C' started by heidik, Nov 10, 2010.

  1. heidik

    heidik New Member

    Joined:
    Oct 23, 2010
    Messages:
    69
    Likes Received:
    0
    Trophy Points:
    0
    I am trying to find out the duplicates in a vector and then display the two vector elements to show that these are the elemenets that were identical (based on some condition). Could anyone please tell me at which point do I have increment itFirst or make itFirst equal to itCurrent in case the second IF is not true or the third IF is not true or the 4th IF is not true. I have tried the itFirst in while loop (i-e matching each itCurrent with all itFirst) but it didnt work.

    HTML:
    std::vector<block>::const_iterator itFirst   = my_file_as_blocks.begin();    // inner loop
            std::vector<block>::const_iterator itCurrent = my_file_as_blocks.begin();    // outer loop
            std::vector<block>::const_iterator itEnd     = my_file_as_blocks.end();
    
            for ( ; itCurrent != itEnd ; ++itCurrent )
            {
            // a for/while for itFirst
    
                if ( itFirst != itCurrent )
                {
            // if order IDs match
            if ( ((itFirst->id1 == itCurrent->id1) || (itFirst->id1 == itCurrent->id2) || (itFirst->id2 == itCurrent->id1) || (itFirst->id2 == itCurrent->id2))
                && ((itCurrent->id1 == itFirst->id1) || (itCurrent->id1 == itFirst->id2) || (itCurrent->id2 == itFirst->id1) || (itCurrent->id2 == itFirst->id2)))
                    {
                if( (itFirst->last_line.find("TIME-DIFF") != std::string::npos )) // if the line stored in last elements of my_file_as_blocks
                {                                          // contains "TIME-DIFF"
                    // only those blocks where time is not the same for "2nd-ORD-TO-WASH-TIME-DIFF"
                    if(itFirst->time_diff != itCurrent->time_diff)
                    {
                            std::cout << "Found a duplicate:" << std::endl;
                    } // end of IF for wash_time_diff not-equal comparison
    
                } // end of IF for existence of "2nd-ORD-TO-WASH-TIME-DIFF"
                    } // end of IF for comparing order IDs
                } // end of if ( itFirst != itCurrent )
            } // end of for ( ; itCurrent != itEnd ; ++itCurrent )
    example my_file_as_blocks
    -------------------------

    HTML:
    123
    456
    789
    012
    345
    123
    567
    789
    123
     

Share This Page