I have written following function, it takes a "block" as an argument, searches for the "block" in a list of blocks "lru". Here "block" is an instance of class "Block". Following is the declaration of "lru":
  list<Block> lru;
And following is my search function:
int LRU::searchLRU(Block block)
{
    if (lru.size() == 0) 
    {
        lru.push_back(block);
        return 1;
    }
    list<Block>::iterator i;
    for (i = lru.begin(); i != lru.end(); i++)              
    {
        if (i->get_set() == block.get_set() && i->get_index() == block.get_index()) 
        {
            lru.push_back(block);
            lru.erase(i);
            return 2;
        }
    }
    if (lru.size() == size)
    {
        lru.pop_front();
        lru.push_back(block);
        return 3;
    } 
}
But the problem is sometimes the function returns "0". And as a result of that my overall program is not functioning properly. I feel i have handled all the cases.
Could someone point out the mistake, or why the function returns "0".
 
     
     
    