Exemplo n.º 1
0
/* Set a new value for the romanized name
 * string value in the GNode data tree, and
 * create a node in the tree if needed.
 */
void GIndiEntry::setRomanizedName(const QString & romanName) {
    // Append a new node to the tree if needed
    if (!_romanNode) {
        // Create the new node
        _romanNode = new GNode("2 ROMN " + romanName);
        // Append it to the end of _nameNode's children
        GNode * n = _nameNode->firstChild();
        if (!n) { // No existing first child
            _nameNode->setFirstChild(_romanNode);
        }
        else { // Pre-existing sub-list
            // Go to the end of the sub-list
            while (n->next()) n = n->next();
            // Append the new node there
            n->setNext(_romanNode);
        }
    }
    // Alter the existing node if needed
    else {
        _romanNode->setData(romanName);
    }
}
/**********************************************************************
 * insert - a sorted insertion
 ***********************************************************************/
void insert(GNode* &listHead, GNode* &aPtr)
{
    //aPtr not rdy to be inserted. Occurs on first individual in parseFile()
    if(aPtr == NULL)
        return;
    //first insertion
    if(listHead == NULL)
    {
        listHead = aPtr;
        return;
    }

    string tempLName = aPtr->getLName();
    string ptrLName;

    for (int i = 0; i < tempLName.length(); i++)
        ptrLName += toupper(tempLName[i]);

    tempLName = listHead->getLName();
    string headLName;
    for (int i = 0; i < tempLName.length(); i++)
        headLName += toupper(tempLName[i]);

    // head insert
    if (ptrLName < headLName)
    {
        aPtr->setNext(listHead);
        listHead = aPtr;
        return;
    }
    else if (ptrLName == headLName && aPtr->getFName() < listHead->getFName())
    {
        aPtr->setNext(listHead);
        listHead = aPtr;
        return;
    }

    GNode* p = listHead;
    GNode* c = listHead->getNext();
    string cLName;

    //traverse, comparing last names,then first Name, then date
    while (c != NULL)
    {
        tempLName = c->getLName();
        cLName.clear();
        for (int i = 0; i < tempLName.length(); i++)
            cLName += toupper(tempLName[i]);

        if (ptrLName > cLName)
        {
            p = c;
            c = c->getNext();
        }
        else if (ptrLName == cLName && aPtr->getFName() > c->getFName())
        {
            p = c;
            c = c->getNext();
        }
        else if (ptrLName == cLName && aPtr->getFName() == c->getFName()
                 && aPtr->getYear() > c->getYear())
        {
            p = c;
            c = c->getNext();
        }
        else
            break;
    }
    p->setNext(aPtr);
    aPtr->setNext(c);
}