void		LittleHand::sortFruitBox(FruitBox& unsorted,
					  FruitBox& lemons,
					  FruitBox& bananas,
					  FruitBox& limes)
{
  FruitBox	tmp(unsorted.nbFruits());
  Fruit*	ret;
  
  while (unsorted.head() && unsorted.head()->elem)
    {
      if (unsorted.head()->elem->getName() == "banana")
	{
	  ret = unsorted.pickFruit();
	  if (!(bananas.putFruit(ret)))
	    tmp.putFruit(ret);
	}
      else if (unsorted.head()->elem->getName() == "lemon")
	{
	  ret = unsorted.pickFruit();
	  if (!(lemons.putFruit(ret)))
	    tmp.putFruit(ret);
	}
      else if (unsorted.head()->elem->getName() == "lime")
	{
	  ret = unsorted.pickFruit();
	  if (!(limes.putFruit(ret)))
	    tmp.putFruit(ret);
	}
      else
	tmp.putFruit(unsorted.pickFruit());;
    }
  while (tmp.head() && tmp.head()->elem)
    unsorted.putFruit(tmp.pickFruit());
}
void            LittleHand::sortFruitBox(FruitBox &unsorted, FruitBox &lemons, FruitBox &bananas, FruitBox &limes) 
{
  FruitNode   *tmp;
  
  tmp = unsorted.head();
  while (tmp != NULL)
    {
      if (tmp->cur_Fru->getName() == "banana")
        {
	  if (bananas.putFruit(tmp->cur_Fru) == true)
            {
	      unsorted.pickFruit();
            }
        }
      if (tmp->cur_Fru->getName() == "lemon")
        {
	  if (lemons.putFruit(tmp->cur_Fru) == true)
            {
	      unsorted.pickFruit();
            }
        }
      if (tmp->cur_Fru->getName() == "lime")
        {
	  if (limes.putFruit(tmp->cur_Fru) == true)
            {
	      unsorted.pickFruit();
            }
        }
      tmp = tmp->next;
    }
}
Exemple #3
0
int	mixage(FruitBox& box) {
  if (box.nbFruits()) {
    FruitNode	*current = box.head();
    int		vita = 0;

    if (!current)
      return 0;
    else {
      while (current->next) {
	vita += current->_fruit->getVitamins();
	current = current->next;
      }
      vita += current->_fruit->getVitamins();
      return vita;
    }
  }
  return 0;
}