Item List::get(int n){ if(n <= 0) return Item("Integer invalid"); ListNode *k = head->getNext(); if(k == NULL) return Item("Not enough items"); //No items if(n == 1) return Item(head->getItem()); //First item on the list for(int i = 2; i < n ; i++){ k = k->getNext(); if(k == NULL) return Item("Not enough items"); } return Item(k->getItem()); //Returns the item of n on the list }
bool List::remove(Item ©) { if (!empty()) // if list is not empty { copy = head->getItem(); // return copy ListNode *tmp = head->getNext(); delete head; // delete the node head = tmp; // update the head if (tmp==NULL) // removed last element tail = NULL; return true; } return false; // nothing in list }
Item List::remove_front(){ Item copy; if (!empty()) // if list is not empty { copy = head->getItem(); // return copy ListNode *tmp = head->getNext(); delete head; // delete the node head = tmp; // update the head if (tmp==NULL) // removed last element tail = NULL; return copy; } else{ return Item("~ERROR~"); } }