Exemple #1
0
bool List:: remove(char& obj)
{
	if(!empty())
		{
		obj = data[cursor];
		int i = cursor;
		while(i < actual -1)
			{
				data[i] =  data[i+1];
				i++;
			}
		
				
		if(cursor == actual)
			{
					gotoBeginning();
			}
			actual--;	
	return true;
		}
	else {
	return false;
	}

}
Exemple #2
0
List::~List()
{
   Node* tmp;
   if(!empty())
   {
      gotoBeginning();

      //loop through all nodes and delete them
      while(cursor != NULL)
      {
         tmp = cursor;
         cursor = cursor->next;
         delete tmp;
      }
   }
}
Exemple #3
0
bool List::remove(char& c)
{
   if(!empty())
   {
      c = cursor->data;
      Node* tmp = cursor;
      
      //use this if the in focus node is not the tail of the list
      if(cursor->next != NULL)
      {
         Node* tmp2 = cursor->next;
         gotoPrior();
         delete tmp;
         tmp = NULL;
         cursor->next = tmp2;
      }
      //use this if the cursor is on the tail
      else
      {
         //check if this is the only node 
         if(cursor == head)
         {
            delete cursor;
            //set to empty
            cursor = NULL;
            head = NULL;
         }
         else
         {
            gotoPrior();
            cursor->next = NULL;
            gotoBeginning();
            delete tmp;
            tmp = NULL;
         }
      }
      return true;
   }
   return false;
}
Exemple #4
0
bool List::clear()
{
   if(!empty())
   {
      gotoBeginning();
      Node* tmp = NULL;

      //loop until last node
      while(cursor != NULL)
      {
         tmp = cursor;
         cursor = cursor->next;
         delete tmp;
      }

      //set cursor to show that list is empty
      cursor = NULL;
      head = NULL;
      return true;
   }
   return false;
}