当前位置: 首页>>代码示例>>C++>>正文


C++ DLNode::getContents方法代码示例

本文整理汇总了C++中DLNode::getContents方法的典型用法代码示例。如果您正苦于以下问题:C++ DLNode::getContents方法的具体用法?C++ DLNode::getContents怎么用?C++ DLNode::getContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DLNode的用法示例。


在下文中一共展示了DLNode::getContents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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++;
    }

  }
}
开发者ID:rickshere,项目名称:CSCI-21-SPRING-2014,代码行数:27,代码来源:DLList.cpp

示例2: 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;
}
开发者ID:Svenzor84,项目名称:CSCI-21-FALL-2015,代码行数:31,代码来源:DLList.cpp

示例3: 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;
    }
 }
开发者ID:ddalton002,项目名称:ddalton002stuff,代码行数:55,代码来源:dl_list.cpp

示例4: 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;
 }
开发者ID:Dminer001,项目名称:CSCI-21,代码行数:18,代码来源:dl_list.cpp

示例5: 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;
    }
}
开发者ID:Svenzor84,项目名称:CSCI-21-FALL-2015,代码行数:49,代码来源:DLList.cpp

示例6: getStop

string DLList::getStop(int iterator) {
    // getStop will loop through the linked list until ITERATIONS is met.
    // It will stop and return where it stopped and do nothing.
    
    // Create TEMP pointer at HEAD
    DLNode* temp = head_node;
    cout << "ITERATOR STARTING; Count = " << iterator << endl;
    for(int i=1;i<iterator;i++) {
        sleep(1);
        temp = temp->getNext();
    }
    cout << "Stopped on: " << temp->getContents() << endl;
    sleep(2);
    return temp->getContents();
}
开发者ID:rhapidfyre,项目名称:CSCI21-SPRING-2016,代码行数:15,代码来源:Declarations.cpp

示例7: 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();
    }
}
开发者ID:rhapidfyre,项目名称:CSCI21-SPRING-2016,代码行数:7,代码来源:Declarations.cpp

示例8: 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);
}
开发者ID:Trongard,项目名称:-CSCI-21-SPRING-2014,代码行数:31,代码来源:DLList.cpp

示例9: 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;
}
开发者ID:JesseKrepelka,项目名称:CSCI-21-FALL-2015,代码行数:11,代码来源:dlist.cpp

示例10: 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;
    }
}
开发者ID:Trongard,项目名称:-CSCI-21-SPRING-2014,代码行数:41,代码来源:DLList.cpp

示例11: 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;}
}
开发者ID:rhapidfyre,项目名称:CSCI21-SPRING-2016,代码行数:39,代码来源:Declarations.cpp

示例12: 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;
}
开发者ID:Trongard,项目名称:-CSCI-21-SPRING-2014,代码行数:15,代码来源:DLList.cpp

示例13: 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;
}
开发者ID:Svenzor84,项目名称:CSCI-21-FALL-2015,代码行数:14,代码来源:DLList.cpp

示例14: 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();
  }
}
开发者ID:rickshere,项目名称:CSCI-21-SPRING-2014,代码行数:14,代码来源:DLList.cpp

示例15: 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();
}
开发者ID:Dminer001,项目名称:CSCI-21,代码行数:24,代码来源:dl_list.cpp


注:本文中的DLNode::getContents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。