本文整理汇总了C++中DLNode::getPrevious方法的典型用法代码示例。如果您正苦于以下问题:C++ DLNode::getPrevious方法的具体用法?C++ DLNode::getPrevious怎么用?C++ DLNode::getPrevious使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DLNode
的用法示例。
在下文中一共展示了DLNode::getPrevious方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insert
void DLList::insert(int newValue) {
if (head == NULL)
pushFront(newValue);
else if (newValue <= head->getContents())
pushFront(newValue);
else if (newValue >= tail->getContents())
pushBack(newValue);
else {
DLNode* spot = head;
while (spot->getNext() != NULL && newValue > spot->getContents())
spot = spot->getNext();
if (spot->getNext() == NULL && newValue >= spot->getContents())
pushBack(newValue);
else {
DLNode* newNode = new DLNode(newValue);
DLNode* trailer = spot->getPrevious();
trailer->setNext(newNode);
newNode->setNext(spot);
newNode->setPrevious(trailer);
spot->setPrevious(newNode);
size++;
}
}
}
示例2: removeFirst
//remove the first instance of a DLNode containing target; do nothing if target is not found
bool DLList::removeFirst (int target)
{
if(head == NULL)
{
return false;
}
else if(head->getContents()==target)
{
popFront();
return true;
}
else
{
DLNode* temp = head;
while(temp->getNext() != NULL)
{
DLNode* nextTemp = temp->getNext();
if(temp->getContents() == target)
{
temp->getPrevious()->setNext(nextTemp);
nextTemp->setPrevious(temp->getPrevious());
delete temp;
size--;
if(size == 1)
{
head = tail;
}
return true;
}
temp = temp->getNext();
}
if(temp->getContents() == target)
{
popBack();
return true;
}
return false;
}
}
示例3: removeFirst
bool DLList::removeFirst(string target) {
if(head_node == NULL) {
return false;
}
DLNode* temp = head_node;
DLNode* previous = temp;
if(head_node->getContents() == target) {
cout << "Eliminated " << target << endl;
popFront();
return true;
}
if(tail_node->getContents() == target) {
cout << "Eliminated " << target << endl;
popBack();
return true;
}
// There is no reason why this loop would be endless, so there won't be a catch.
// The incoming TARGET string is only called when getStop finishes.
while(temp->getContents() != target) {
// Get next node and continue, and keep previous 1 behind.
previous = temp;
temp = temp->getNext();
}
if(temp->getContents() == target) {
cout << "Eliminated " << target << endl;
// Delete Node
// Setting previous' node to the next node of temp
previous->setNext(temp->getNext());
// Setting temp's next node's PREVIOUS to temp's previous NODE
temp->setPrevious(temp->getPrevious());
delete temp;
temp = NULL;
node_count--;
return true;
} else {
cout << "RemoveFirst returned false entirely (bad?)"<<endl;return false;}
}