Demo entry 6691663

cpp

   

Submitted by jile on Jan 12, 2018 at 14:35
Language: C++. Code size: 1.7 kB.

int compare(deque<int> listA,deque<int> listB)
{
    int counter = 0 ;

    deque<int>::iterator frontListA ;
    deque<int>::iterator lastListA  ;
    deque<int>::iterator frontListB  ;
    deque<int>::iterator lastListB  ;

    while(!listA.empty())
    {
        frontListA = listA.begin() ;
        lastListA = listA.end() ;
        frontListB = listB.begin() ;
        lastListB = listB.end() ;

        if(*frontListB > *frontListA )
        {
            counter++ ;
            listA.pop_front() ;
            listB.pop_front() ;
           // frontListA = listA.erase(frontListA) ;
           // frontListB = listB.erase(frontListB) ;
        }
        else if(*frontListB < *frontListA)
        {
            counter-- ;
            listB.pop_back() ;
            listA.pop_front() ;
            //listB.erase(lastListB) ;
            //listA.erase(frontListA) ;
        }
        else
        {
            if(*lastListB > *lastListA)
            {
                counter++ ;
                listA.pop_back() ;
                listB.pop_back() ;
                //listA.erase(lastListA) ;
                //listB.erase(lastListB) ;
            }
            else if(*lastListB < *lastListB)
            {
                counter-- ;
                listB.pop_back() ;
                listA.pop_front() ;
                //listB.erase(lastListB) ;
                //listA.erase(frontListA) ;
            }
            else
            {
                listA.pop_back() ;
                listB.pop_back() ;
                //listA.erase(lastListA) ;
                //listB.erase(lastListB) ;
            }

        }
    }

    return counter ;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).