Example #1
0
void PtrListRep::remove(void* element)
{
    if(element!=NULL && _first!=NULL)
    {
        for(ListNode* n=_first; n!=NULL; n=n->getNext())
        {
            void* el = n->getElement();
            if(el==element)
            { // remove the node
                ListNode* prev = n->getPrevious();
                ListNode* next = n->getNext();

                if(prev!=NULL)
                    prev->setNext(next);
                else // the node is the very first
                    _first = next;

                if(next!=NULL)
                    next->setPrevious(prev);
                else // the node is the last
                    _last = prev;

                delete n;
                break;
            }
        }
    }
}
Example #2
0
bool List::remove(Object* const object)
{
	bool objectFound = false;

	ListNode* temp = this->first; 
	ListNode* prev = NULL;
	ListNode* next = NULL;

	while( temp != NULL ) {
		if (object == temp->getObject()) {
			next = temp->getNext();
			delete temp;
			if(next == NULL)
				last = NULL;
			if(prev == NULL)
				first = next;
			else
				prev->setNext(next);
			objectFound = true;
			break;
		}
		prev = temp;
		temp = temp->getNext();
	}
	return objectFound;
}
Example #3
0
void KdTree::add( KdTreeNode* kdnode, Object* ob )
{
	//std::cout<<_buffer_l<<std::endl;
	ListNode* node = &_ListNodeBuffer[_buffer_l++];
	node->setObject( ob );
	node->setNext( kdnode->getList() );
	kdnode->setList( node );
}
Example #4
0
// Add to the end of the list
ListNode * LinkedList::append(const int val)
{
  ListNode *node = &head;

  while (node->hasNext()) {
    node = node->getNext();
  }
  return node->setNext(new ListNode(val));
}
Example #5
0
void List<Object>::remove( const Object& data ) {
	ListIterator<Object> iter = findPrevious( data );
	if (iter.isValid()) {
		ListNode<Object>* node = findPrevious( data ).current;
		if (node->getNext() != NULL) {
			ListNode<Object> *oldNode = node->getNext();
			node->setNext( node->getNext()->getNext() );  // Skip oldNode
			delete oldNode;
		}
	}
}
Example #6
0
// Insert in sorted order (ascending)
ListNode * LinkedList::insert(const int val)
{
  ListNode *node = head.getNext();
  ListNode *prev = &head;

  while (node != 0 && node->getVal() < val) {
    prev = node;
    node = node->getNext();
  }
  return prev->setNext(new ListNode(val, prev->getNext()));
}
Example #7
0
void PtrListRep::add(void* element)
{
    ListNode* n = new ListNode(element);

    if(_last==NULL)
    { // this is the very first one
        _first = _last = n;
    }
    else { // append to the end
        _last->setNext(n);
        n->setPrevious(_last);
        _last = n;
    }
}
Example #8
0
File: hw2.cpp Project: APeeples/BS
void List::push_back(const char * a){
	Item b(a);
	ListNode *node = new ListNode(b);
	if (head == NULL)
    {
      // list is empty
      head = node;
      tail = node;
    }
  else 
    {
      tail->setNext(node);
      tail = node;
    }
}
Example #9
0
File: hw2.cpp Project: APeeples/BS
void List::append(Item a)
{
  ListNode *node = new ListNode(a);
  if (head == NULL)
    {
      // list is empty
      head = node;
      tail = node;
    }
  else 
    {
      tail->setNext(node);
      tail = node;
    }
}
Example #10
0
void List::Insert(int newInt){
	if(head==NULL){
		ListNode * h = new ListNode(newInt,NULL);
		head=h;
	}
	else{
		ListNode * index = head;
		ListNode * prev = NULL;
		ListNode * newListNode = new ListNode(newInt);
		while(index->getNext()!=NULL && index->getMyInt()<=newInt){
			prev=index;
			index=index->getNext();
		}
		if(index->getMyInt()>newInt){
			newListNode->setNext(index);
			if(prev!=NULL)
				prev->setNext(newListNode);
			else
				head=newListNode;
		}
		else
			index->setNext(newListNode);
	}
}
Example #11
0
// Remove the first node having the specified value (if present)
int LinkedList::remove(const int val)
{
  ListNode *node = head.getNext();
  ListNode *prev = &head;

  while (node != 0 && node->getVal() != val) {
    prev = node;
    node = node->getNext();
  }
  if (node->getVal() == val) {
    prev->setNext(node->getNext());
    delete node;
    return val;
  }
  return -1;
}
void OrderedDictionary::makeListReverseOrder(OrderedDictionaryEntry *entry,
        ListNode *&head)
{
    if(entry == NULL)
        return; // árbol vacío, no hay nada que hacer
    
    makeListReverseOrder(entry->getLesser(), head);
    
    // pone el elemento actual al final y crea la lista si estaba en NULL
    if(head == NULL){
        head = new ListNode(entry->getVal());
    } else {
        ListNode *entryNode = new ListNode(entry->getVal());
        entryNode->setNext(head);
        head = entryNode;
    }
    
    makeListReverseOrder(entry->getGreater(), head);
}
Example #13
0
void List::remove(ICollectible *c)
{
    ListNode *current = head;
    ListNode *previous = NULL;
    while(current != NULL && current->getElem() != c){
        previous = current;
        current = current->getNext();
    }

    if(current == NULL){ // final de la lista, no estaba
        return;
    } else if(current->getElem() == c){ // ya está, se borra
        --size;
        if(previous == NULL) // se borra el primer elemento
            head = current->getNext();
        else
            previous->setNext(current->getNext());
        delete current;
    }
}
Example #14
0
void List::add(ICollectible* c)
{
    if(head == NULL){ // list vacía; tamaño = 1
        head = new ListNode(c);
        size = 1;
        return;
    }
    
    ListNode *current = head;
    ListNode *previous;
    while(current != NULL && current->getElem() != c){
        previous = current;
        current = current->getNext();
    }
    
    if(current == NULL){ // final de la lista, se agrega
        previous->setNext(new ListNode(c));
        ++size;
    }
}
Example #15
0
// Insert at the beginning of the list
ListNode * LinkedList::prepend(const int val)
{
  return head.setNext(new ListNode(val, head.getNext()));
}