Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool FruitBox::putFruit(Fruit *f) {
- if (this->nbFruit >= this->size)
- return false;
- if (this->list == NULL) {
- this->list = new FruitNode();
- this->list->fruit = f;
- this->list->next = NULL;
- this->nbFruit++;
- return true;
- }
- FruitNode* tmp = this->list;
- FruitNode* elem = new FruitNode();
- while (tmp->next != NULL) {
- if (tmp->fruit == f)
- return false;
- tmp = tmp->next;
- }
- elem->fruit = f;
- elem->next = NULL;
- tmp->next = elem;
- this->nbFruit++;
- return true;
- }
- Fruit *FruitBox::pickFruit() {
- Fruit *f;
- if (this->list) {
- f = this->list->fruit;
- this->list = this->list->next;
- } else f = 0;
- this->nbFruit--;
- return f;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement