示例#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;
}
示例#2
0
node::node (const node& inNode)
{
    priority = inNode.getPriority();
    value = inNode.getValue();
    size = inNode.getSize();
    sum = inNode.getSum();
    max = inNode.getMax();
    min = inNode.getMin();
    isIncreasing = inNode.getIsIncreas();
    isDecreasing = inNode.getIsDecreas();
    needToRev = inNode.getNeedToRev();

    left = inNode.getLeft();
    right = inNode.getRight();
}
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;
}