Exemplo n.º 1
0
Arquivo: hw2.cpp Projeto: APeeples/BS
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
}
Exemplo n.º 2
0
Arquivo: hw2.cpp Projeto: APeeples/BS
bool List::remove(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 true;
    }
  return false; // nothing in list
}
Exemplo n.º 3
0
Arquivo: hw2.cpp Projeto: APeeples/BS
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~");
    }
}