Пример #1
0
bool ListN:: remove(int& c)  
{
	if(!empty())
	{
		if(head == cursor)
		{
			cursor = cursor->next;
			//head->next = NULL;
			delete head;
			head = cursor;
		}
	else if( cursor-> next == NULL)
	{
		Node* temp = cursor;
		gotoPrior();
		cursor->next = NULL;
		delete temp;
		cursor = head;
	}
		else {
			Node* temp = cursor;
			gotoPrior();
			cursor->next = temp->next;
			//temp->next = NULL;
			delete temp;
			}
		return true;
	}
	return false;
				
}
Пример #2
0
bool List::remove(char&output) {
    if(empty()) {
        return false;
    }
    output = cursor->data;
    if(head == cursor) {
        delete cursor;
        head = cursor = NULL;
        return true;
    }
    if(cursor->next == NULL) {
        Node* tmp = cursor;
        gotoPrior();
        cursor->next = NULL;
        delete tmp;
        tmp = NULL;
        cursor = head;
        return true;
    }
    Node* temp = cursor;
    gotoPrior();
    cursor = cursor->next = temp->next;
    delete temp;
    temp = NULL;
    return true;

    //remove the value at the cursor, leave the cursor in place.
    //if last element, move cursor to the beginning of the list
    //return removed value
}
Пример #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;
}
Пример #4
0
bool ListN::remove(int& c)
{
	if(!empty())
	{
		c = cursor->data;
		Node* temp = cursor->next;
		delete cursor;
		gotoPrior();
		cursor->next = temp;
	}
	else
		return false;
	return true;
}