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());
}
Beispiel #2
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;
}