Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   where to increment vector iterator (http://www.go4expert.com/forums/increment-vector-iterator-t23823/)

heidik 10Nov2010 21:38

where to increment vector iterator
 
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 Code:

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 Code:

123
456
789
012
345
123
567
789
123



All times are GMT +5.5. The time now is 17:37.