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


C++ ListNode::GetNextListNode方法代码示例

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


在下文中一共展示了ListNode::GetNextListNode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: displayList

void CountryList::displayList() const
{
  ListNode *nodePtr;

  nodePtr = head->GetNextListNode();

  //Display the header
  cout << setfill('-');
  cout << setw(6) << "Code";
  cout << setw(20) << "Country";
  cout << setw(20) << "Capital";
  cout << setw(15) << "Population" << endl;
  for (int i = 0; i < 61; i++) { cout << '-'; }

  cout << endl << setfill(' ');
  while (nodePtr) {
    // Display the information in the current node.
    cout << setw(5) << nodePtr->GetCountry().GetCode() << " ";
    cout << setw(20) << nodePtr->GetCountry().GetName();
    cout << setw(20) << nodePtr->GetCountry().GetCapital();
    cout << setw(15) << nodePtr->GetCountry().GetPopulation() << endl;
    // Move to the next node.
    nodePtr = nodePtr->GetNextListNode();
  }
  cout << endl;
}
开发者ID:rbaheti,项目名称:CIS-22C-HW1-Linked-List,代码行数:26,代码来源:CountryList.cpp

示例2: deleteNode

//**************************************************
// The deleteNode function searches for a node
// with code as its code. The node, if found, is
// deleted from the list and from memory.
// It returns an error code
//      -1 represents an empty list
//      0 means the country was not found
//      1 means the country was deleted
//**************************************************
int CountryList::deleteNode(const char* code)
{
  ListNode *nodePtr;       // To traverse the list
  ListNode *previousNode = NULL;  // To point to the previous node

                           // check if list is empty
  if (cnt == 0)
    return -1; // -1 for empty list

  nodePtr = head->GetNextListNode();
  // Search for the node to be deleted from the list
  while (nodePtr != NULL && strcmp(nodePtr->GetCountry().GetCode(), code) != 0) {
    previousNode = nodePtr;
    nodePtr = nodePtr->GetNextListNode();
  }
  if (nodePtr) { // found
    previousNode->SetNextListNode(nodePtr->GetNextListNode());
    delete nodePtr;
    cnt--;
    return 1; // 1 for success
  }
  return 0; // 0 for not found
}
开发者ID:rbaheti,项目名称:CIS-22C-HW1-Linked-List,代码行数:32,代码来源:CountryList.cpp

示例3: while

CountryList::~CountryList()
{
  ListNode *nodePtr;   // To traverse the list
  ListNode *nextNode;  // To point to the next node

                       // Position nodePtr at the head of the list.
  nodePtr = head;

  // While nodePtr is not at the end of the list...
  while (nodePtr != NULL) {
    // Save a pointer to the next node.
    nextNode = nodePtr->GetNextListNode();
    // Delete the current node.
    delete nodePtr;
    // Position nodePtr at the next node.
    nodePtr = nextNode;
  }
}
开发者ID:rbaheti,项目名称:CIS-22C-HW1-Linked-List,代码行数:18,代码来源:CountryList.cpp

示例4: findCountry

//**************************************************
// Searches the list for a given country code
//  - returns a pointer to the country if found
//  - returns NULL if the country cannot be found
//**************************************************
Country* CountryList::findCountry(const char* code) {
  ListNode *nodePtr;       // To traverse the list
  ListNode *previousNode;  // To point to the previous node

                           // If the list is empty, return NULL
  if (cnt == 0)
    return NULL;

  nodePtr = head->GetNextListNode();
  previousNode = head;

  while (nodePtr != NULL && strcmp(nodePtr->GetCountry().GetCode(), code)) {
    previousNode = nodePtr;
    nodePtr = nodePtr->GetNextListNode();
  }

  if (nodePtr) { // found
    return &nodePtr->GetCountry();
  }
  return NULL;
}
开发者ID:rbaheti,项目名称:CIS-22C-HW1-Linked-List,代码行数:26,代码来源:CountryList.cpp

示例5: insertNode

//**************************************************
// The insertNode function inserts a node with
// countryIn copied to its country member.
//**************************************************
void CountryList::insertNode(Country countryIn)
{
  ListNode *newNode;             // A new node
  ListNode *nodePtr;             // To traverse the list
  ListNode *previousNode = NULL; // The previous node

                                 // Allocate a new node and store the country there.
  newNode = new ListNode;
  newNode->SetCountry(countryIn);

  previousNode = head;
  nodePtr = head->GetNextListNode();
  // Find the location of the new node in the sorted list
  while (nodePtr != NULL && strcmp(nodePtr->GetCountry().GetCode(), countryIn.GetCode()) < 0) {
    previousNode = nodePtr;
    nodePtr = nodePtr->GetNextListNode();
  }
  // Update links and counter
  previousNode->SetNextListNode(newNode);
  newNode->SetNextListNode(nodePtr);
  cnt++;
}
开发者ID:rbaheti,项目名称:CIS-22C-HW1-Linked-List,代码行数:26,代码来源:CountryList.cpp


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