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


C++ Child::getSibling方法代码示例

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


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

示例1: addChild

/*
 * This function adds a child to the family. The child is inserted at the of the
 * linked list of children. In order to i=add the child to the end of the list, 
 * the function checks whether the list is empty, if there is already one child,
 * or if there are more than one child. If there is no children in list, the 
 * child is added at the head of the list. If there is already one child, the 
 * the child is added after the first child. If there is more than one child in
 * the list, then the end of the list is searched for and the child is added at
 * the end.
 *
 * @param: Child* const &child - pointer to child to be added to list of children
 * @attribute: Child *children - head pointer to linked list of children   
 */
void Wife::addChild(Child* const &child)
{
  if(children == NULL){
    children = child;
  }
  else if(children->getSibling() == NULL){
    children->setSibling(child);
  }
  else{
    Child *curr = children;
    while(curr->getSibling() != NULL){
      curr = curr->getSibling();
    }
    curr->setSibling(child);
  }
}
开发者ID:ipkCoder,项目名称:cs211,代码行数:29,代码来源:Wife.cpp

示例2: printChildren

/*
 * This function prints the names of all the children in the family.
 *
 * @attribute: Child *children - head pointer to linked list of children
 */
void Wife::printChildren()
{
  Child *child = children;
  
  while(child != NULL){
    child->print();
    child = child->getSibling();
  }
}
开发者ID:ipkCoder,项目名称:cs211,代码行数:14,代码来源:Wife.cpp

示例3: removeChild

/*
 * This function removes a child from the linked list of children. The child is 
 * searched for using their social security number. To search the list and delete 
 * a child, two steps must be performed. The first step is to check if the first
 * chlid in the list is the child to be deleted. If not, then the rest of the 
 * list is searched. These two steps are necessary because they each require
 * different procedures to remove a child from the list.
 *
 * @param: const long &ssn - social security number associated with child 
 *                           to search for
 * @attribute: Child *children - head pointer to linked list of children
 */
bool Wife::removeChild(const long &ssn)
{
  if(children == NULL){
    return false;
  }
  
  // check if first child is to be removed
  if(children->getSSN() == ssn){
    Child *child = children;
    children = child->getSibling();
    delete child;
    return true;
  }
  
  // set current child to second child and previous child to first child
  Child *prevChild = children;
  Child *currChild = children->getSibling();
  
  // if child exists in the rest of the list of children, point previous
  // child's sibling pointer to the child after the child to be deleted
  while(currChild != NULL){
    if(currChild->getSSN() == ssn){
      prevChild->setSibling(currChild->getSibling());
      break;
    }
    else{
      prevChild = currChild;
      currChild = currChild->getSibling();
    }
  }
  
  // if child found, delete child and return true, else false
  if(currChild != NULL){
    delete currChild;
    return true;
  }
  else{
    return false;
  }
}
开发者ID:ipkCoder,项目名称:cs211,代码行数:52,代码来源:Wife.cpp

示例4: removeChildren

/*
 * This function removes all children from a family. 
 *
 * @attribute: Child *children - head pointer to linked list of children
 */
void Wife::removeChildren()
{
  Child *child = children;
  Child *temp = NULL;
  
  while(child != NULL){
    temp = child;
    child = child->getSibling();
    delete temp;
  }
  
  children = NULL;
}
开发者ID:ipkCoder,项目名称:cs211,代码行数:18,代码来源:Wife.cpp

示例5: searchForChild

/*
 * This function searches for a child in a family by searching for the child's 
 * social security number in the linked list of children. 
 *
 * @return: true if child's social security number is found, else false
 */
bool Wife::searchForChild(const long &ssn)
{
  Child *curr = children;
  bool found = false;
  
  while(curr != NULL){
    if(curr->getSSN() == ssn){
      found = true;
      break;
    }
    else
      curr = curr->getSibling();
  }
  
  return found;
}
开发者ID:ipkCoder,项目名称:cs211,代码行数:22,代码来源:Wife.cpp


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