本文整理汇总了C++中DLNode类的典型用法代码示例。如果您正苦于以下问题:C++ DLNode类的具体用法?C++ DLNode怎么用?C++ DLNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DLNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
}
示例2: 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();
}
}
示例3: 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;
}
示例4: DLNode
/**
* creates a new dynamic DLNode with the contents of
* the parameter and attaches as the new head of the list
* @param string contents
*/
void DLList::pushFront(string contents)
{
DLNode* temp = new DLNode(contents);
temp->setNext(head_);
temp->setPrevious(tail_);
head_ = temp;
size_ += 1;
if (tail_ == NULL)
tail_ = head_;
}
示例5: pushFront
void DLList::pushBack(int value) {
if (head == NULL) {
pushFront(value);
} else {
DLNode* newTail = new DLNode(value);
newTail->setPrevious(tail);
tail->setNext(newTail);
tail = newTail;
size++;
}
}
示例6: Exists
bool DLList::Exists(int value){
DLNode* temp = head;
while (temp != NULL) {
if (temp->GetContents() == value) {
return true;
}
temp = temp->GetNext();
}
return false;
}
示例7: get
bool DLList::get(int target) const{
DLNode* node = head;
bool isPresent = false;
while(node->getNextNode() != NULL){
if(node->getContents() == target){
isPresent = true;
}
node->setNextNode(node->getNextNode());
}
return isPresent;
}
示例8: DLNode
void DLList::pushFront(int newContents){
DLNode* node = new DLNode(newContents);
if (head == NULL){
tail = node;
}
else{
node->setNextNode(head);
}
head = node;
size++;
}
示例9: if
/**
* 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;
}
}
示例10: DLNode
void DLList::pushFront(int value) {
DLNode* newHead = new DLNode(value);
if (head == NULL) {
head = newHead;
tail = head;
size++;
} else {
newHead->setNext(head);
head->setPrevious(newHead);
head = newHead;
size++;
}
}
示例11: pushFront
void DLList::pushBack(int newContents){
if(head == NULL){
pushFront(newContents);
}
else{
DLNode* node = new DLNode(newContents);
DLNode* b = head;
while(b->getNextNode() != NULL){
b = b->getNextNode();
}
b->setNextNode(node);
size++;
}
}
示例12: string
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();
}
}
示例13: pushFront
/**
* 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);
}
}
}
示例14: 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;
}
示例15: get
/**
* returns true if parameter is in the list
* else returns false
*/
bool DLList::get(string contents)
{
DLNode* temp = head_;
while (temp != tail_)
{
if (temp->getContents() == contents)
return true;
if (temp->getContents() != contents)
{
temp = temp->getNext();
}
}
return false;
}