Exemplo n.º 1
0
bool DoublyLinkList::deleteFromList(int val)
{
	node *curr;
	if (!head || !tail)
	{
		return false;
	}
	if (head->getNext() == NULL || tail->getPrev() == NULL)
	{
		curr = head;
		head = tail = NULL;
		delete curr;
		return true;
	}
	if (head->getValue() == val)
	{
		curr = head->getNext();
		curr->setPrev(NULL);
		delete head;
		head = curr;
		return true;
	}
	if (tail->getValue() == val)
	{
		curr = tail->getPrev();
		curr->setNext(NULL);
		delete tail;
		tail = curr;
		return true;
	}

	curr = head;
	while (curr)
	{
		if (curr->getValue() == val)
		{
			curr->getNext()->setPrev(curr->getPrev());
			curr->getPrev()->setNext(curr->getNext());
			delete curr;
			return true;
		}
		curr = curr->getNext();
	}
	return false;
}
Exemplo n.º 2
0
    node& pop() {
        if(!isEmpty())
        {
            node *ret;
            ret = head;
            head = &(head->getNext());

            count--;
            return *ret;
        }

    }
int Stack::pop()
{
	int val;
	if (head)
	{
		val = head->getValue();
		node *temp = head->getNext();
		delete head;
		head = temp;
	}
	else
	{
		cout << "Stack is empty" << endl;
		val = -1;
	}

	return val;
}