本文整理汇总了C++中DLNode::getNext方法的典型用法代码示例。如果您正苦于以下问题:C++ DLNode::getNext方法的具体用法?C++ DLNode::getNext怎么用?C++ DLNode::getNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DLNode
的用法示例。
在下文中一共展示了DLNode::getNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insert
/**
* Insert function that creates a new node and
* inserts it in an appropriate location in the list.
*@param string contents the contents of the new node.
*/
void DLList::insert(string contents)
{
//Checks if head is null or contents is < head_->getContents();
if (head_ == NULL)
{
pushFront(contents);
} else if ( tail_->getContents() < contents)
{
// cout << " got it: " << contents << endl;
// cout << ToString();
pushBack(contents);
} else
{
//creates iterator and newnode
DLNode* iterator;
iterator = head_;
while (iterator->getNext() != tail_ && contents > iterator->getNext()->getContents())
{
iterator = iterator->getNext();
}
if (iterator != tail_)
{
DLNode *newNode = new DLNode(contents);
newNode->setNext(iterator->getNext());
iterator->setNext(newNode);
size_ +=1;
} else
{
pushBack(contents);
}
}
}
示例2: 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++;
}
}
}
示例3: removeFirst
bool DLList::removeFirst(int target) {
DLNode* toRemove = NULL;
DLNode* nodeMark = head;
DLNode* lagMark = NULL;
for (unsigned int i = 0; i < count; i++){
if (nodeMark->getContents() != target && nodeMark->getNext() != NULL){
lagMark = nodeMark;
nodeMark = nodeMark->getNext();
} else if (nodeMark->getContents() == target){
toRemove = nodeMark;
}
}
if (toRemove == NULL) {
return false;
}
if (lagMark == NULL){
popFront();
} else if (toRemove->getNext() == NULL) {
popBack();
} else {
count--;
nodeMark = nodeMark->getNext();
lagMark->setNext(nodeMark);
nodeMark->setPrevious(lagMark);
delete toRemove;
}
toRemove = NULL;
nodeMark = NULL;
lagMark = NULL;
return true;
}
示例4: insert
//create new DLNode with newContents and insert in ascending (based on newContents) order
void DLList::insert (int newContents)
{
if(head == NULL || newContents < head->getContents())
{
pushFront(newContents);
return;
}
DLNode* temp = head;
while(temp->getNext() != NULL)
{
DLNode* nextTemp = temp->getNext();
if(nextTemp->getContents() > newContents)
{
DLNode* inserted = new DLNode(newContents);
inserted->setPrevious(temp);
inserted->setNext(nextTemp);
temp->setNext(inserted);
nextTemp->setPrevious(inserted);
size++;
return;
}
temp = temp->getNext();
}
pushBack(newContents);
}
示例5: insert
/**
* create new DLNode with newContents and insert in ascending (based on
* newContents) order
*/
void DLList::insert(int newContents)
{
/**
* Checks to see if head_ is null or if the contents of head_ are greater
* then the parameter being inserted. If it is then calls the
* pushFront() function, otherwise continues to next check
*/
if(head_ == NULL || head_->getContents() > newContents)
{
pushFront(newContents);
/**
* Checks if the contents of tail_ are less then the parameter being
* inserted. If so, calls pushBack() function, otherwise continues
* to next check
*/
} else if (tail_->getContents() < newContents)
{
pushBack(newContents);
/**
* Inserts the parameter into the correct location in the list
*/
} else
{
DLNode* iterator;
iterator = head_;
/**
* Checks whether the contents of the next node is less then the parameter
* and that the next node is not the tail. If they are not, then it
* advances the iterator to the next node in the list
*/
while(newContents > iterator->getNext()->getContents() && iterator->getNext() != tail_)
{
iterator = iterator->getNext();
}
/**
* Checks if the iterator is located at the tail
*/
if(iterator != tail_)
{
/**
* If the iterator is not located at the tail, it creates a new node
* and inserts it at the iterators current location, then increases
* the size variable by 1
*/
DLNode* new_node = new DLNode(newContents);
new_node->setNext(iterator->getNext());
//new_node->setPrevious(iterator);
iterator->setNext(new_node);
count_ = count_ + 1;
} else
{
/**
* If the iterator is located at the tail, then calls the InsertTail()
* function
*/
pushBack(newContents);
}
}
}
示例6: get
/**
* return true if target is in list, else return false
*/
bool DLList::get(int target) const
{
/**
* Checks if the head is null and returns false if it is
*/
if(head_ == NULL)
{
return false;
/**
* Checks if the contents of head_ are equal to the parameter and returns true if it is
*/
} else if(head_->getContents() == target)
{
return true;
/**
* Checks if the contents of tail_ are equal to the parameter and returns true if it is
*/
} else if(tail_->getContents() == target)
{
return true;
/**
* checks if the list contains only two nodes, if it does not then
* it checks for the specified parameter, otherwise it returns false
*/
} else if(head_->getNext() != tail_)
{
DLNode* iterator = head_->getNext();
/**
* Loops through the node list checking the contents of the current
* node to the parameter and if the next node is the tail, if neither
* statement is true then it iterates to the next node
*/
while(iterator->getContents() != target && iterator->getNext() != tail_)
{
iterator = iterator->getNext();
}
/**
* Checks if the contents of the current node are equal to the parameter
* and returns true, if not then returns false
*/
if(iterator->getContents() == target)
{
return true;
} else
{
return false;
}
} else
{
return false;
}
}
示例7: while
//display the contents of each node in the list, formatted per the program specification ("NUM1,NUM2,NUM3,...,NUMX"), to the output stream out
ostream& operator<< (ostream& out, const DLList src)
{
DLNode* temp = src.head;
stringstream returned;
while(temp != NULL)
{
returned << temp->getContents();
if(temp->getNext() != NULL)
returned << ", ";
temp=temp->getNext();
}
out << returned.str();
return out;
}
示例8: get
bool DLList::get(int target) const {
DLNode* nodeMark = head;
bool targetFound = false;
for (unsigned int i = 0; i < count; i++) {
if (nodeMark->getContents() == target){
targetFound = true;
}
if (nodeMark->getNext() != NULL) {
nodeMark = nodeMark->getNext();
}
}
nodeMark = NULL;
return targetFound;
}
示例9: toString
string DLList::toString() const {
if (head == NULL)
return string("");
else {
stringstream ss;
for (DLNode* i = head; i != NULL; i = i->getNext()) {
ss << i->getContents();
if ((i->getNext()) != NULL)
ss << ',';
}
return ss.str();
}
}
示例10: insert
void DLList::insert(int newContents) {
if (head == NULL) {
pushFront(newContents);
} else {
count++;
DLNode* newNode = new DLNode(newContents);
if (head->getContents() > newContents){
DLNode* oldHead = head;
head = newNode;
head->setNext(oldHead);
oldHead->setPrevious(head);
oldHead = NULL;
} else {
if (head->getNext() == NULL) {
head->setNext(newNode);
newNode->setPrevious(head);
tail = newNode;
} else {
DLNode* nodeMark = head->getNext();
DLNode* lagMark = NULL;
for (unsigned int i = 1; i < count; i++) {
if (nodeMark->getContents() < newContents && nodeMark->getNext() != NULL) {
lagMark = nodeMark;
nodeMark = nodeMark->getNext();
}
}
if ((lagMark == NULL) && (nodeMark->getNext() != NULL || nodeMark->getContents() > newContents)) {
head->setNext(newNode);
newNode->setNext(nodeMark);
nodeMark->setPrevious(newNode);
newNode->setPrevious(head);
} else if (nodeMark->getNext() == NULL && newContents > nodeMark->getContents()) {
nodeMark->setNext(newNode);
newNode->setPrevious(nodeMark);
tail = newNode;
} else {
lagMark->setNext(newNode);
newNode->setNext(nodeMark);
nodeMark->setPrevious(newNode);
newNode->setPrevious(lagMark);
}
nodeMark = NULL;
lagMark = NULL;
}
}
newNode = NULL;
}
}
示例11: removeAll
//removes node from head
bool DLList::removeAll(int target)
{
if (head == NULL)
return false;
else
{
DLNode* trailer = NULL;
DLNode* spot = head;
while(spot != NULL &&spot -> getContents() != target)
{
trailer = spot;
spot = spot -> getNext();
}
if(spot == NULL)
return false;
else if(spot == head)
{
popFront();
return true;
}
else
{
trailer -> setNext(spot->getNext());
delete spot;
count--;
return true;
}
}
}
示例12: debugger
void DLList::debugger() {
DLNode* temp = head_node;
for(int i=0;i<node_count;i++) {
cout << " Node #" << i << " returns as " << temp->getContents() << endl;
temp = temp->getNext();
}
}
示例13: popBack
void DLList::popBack() {
// Remove current head node; do nothing if list is empty
if (tail_node != NULL) {
DLNode* temp = head_node;
DLNode* previous = temp;
while(temp->getNext() != tail_node) {
previous = temp;
temp = temp->getNext();
}
previous->setNext(head_node);
head_node->setPrevious(previous);
delete tail_node;
tail_node = previous;
temp = NULL;
node_count--;
}
}
示例14: ToString
/* DLNode* temp = contents.getFront();
while (temp != NULL)
{
out << temp->getContents();
temp = temp->getNext();
}*/
string DLList::ToString() const
{
if (head_ == NULL)
return "";
stringstream ss;
DLNode* temp = head_;
while (temp != NULL)
{
ss << temp->getContents();
if (temp->getNext() != NULL)
ss << ", ";
temp = temp->getNext();
}
return ss.str();
}
示例15: searchIndex
DLNode* DLList::searchIndex(int targetValue) const {
DLNode* nodeInQuestion = head;
for (unsigned int i = 0; i < size; i++) {
if (nodeInQuestion -> getContents() == targetValue) {
return nodeInQuestion;
} else
nodeInQuestion = nodeInQuestion->getNext();
}
return 0;
}