本文整理汇总了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);
}
}
示例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();
}
}
示例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;
}
}
示例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;
}
示例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;
}