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


C++ list::getElemName方法代码示例

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


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

示例1: RETURN

//Alt. version of buildPath()
std::list< std::list<Node>::iterator >
    Graph::buildPath2(std::list<Node>::iterator pbaseNode, std::list<Node>::iterator ptargetNode)
{
    std::list< std::list<Node>::iterator > emptyPath;
    std::list< std::list<Node>::iterator > path;
    path.push_back(pbaseNode);

    //make sure iterators are valid
    std::list<Node>::iterator pnull = std::list<Node>::iterator(NULL);
    if (pbaseNode == pnull || ptargetNode == pnull)
    {
        std::cout << "\nFALSE BUILD2 RETURN (null iterators)";
        return path;
    }

    std::vector<short> baseWord = pbaseNode->getElemName();
    std::vector<short> targetWord = ptargetNode->getElemName();


    //target word must be longer than or equal length as base word
    if (targetWord.size() < baseWord.size())
        return emptyPath;
    //should never touch the identity; this is a special case which is handled in initial step
    if (baseWord[0] == 0 || targetWord[0] == 0)
        return emptyPath;
    //if words are identical there's nothing to do
    if (baseWord == targetWord)
        return path;

    //At this point we know the nodes exist, their words have appropriate sizes, they're not the identity,
    //and they're not equal. But we could still have the problem that the base word is not contained
    //in the leftmost portion of the target word, so we check for that.
    bool baseContained = true;
    int i;
    for (i = 0; i < baseWord.size() - 1; i++)  //up until the last letter, each exponent identical
        if (baseWord[i] != targetWord[i])
            baseContained = false;
    if (baseWord[i] > targetWord[i])  //on the last letter, the exponent in base may be less or equal
        baseContained = false;
    if (baseContained == false)
        return emptyPath;


    //Now we know that we can build a valid path from the base node to the target node.

    //this first part handles the first exponent on baseWord if it doesn't match targetWord
    std::list<Node>::iterator pcurrentNode = pbaseNode; //will be updated to point to the farthest node in the path
    if (baseWord[i] < targetWord[i])
    {
        if (i % 2 == 0) //if baseWord[i] is an exponent of x
            for (int j = baseWord[i]; j <= targetWord[i]; j++)
            {
                pcurrentNode = buildXprod(pcurrentNode);
                path.push_back(pcurrentNode);
            }
        else            //if baseWord[i] is an exponent of y
            for (int j = baseWord[i]; j <= targetWord[i]; j++)
            {
                pcurrentNode = buildYprod(pcurrentNode);
                path.push_back(pcurrentNode);
            }
    }

    //now build the path up to the last exponent of targetWord (handled specially below)
    //note: i currently points to the last letter in baseWord, so it must be incremented to start one after that
    i++;
    for (i = i; i < targetWord.size() - 1; i++)
    {
        if (i % 2 == 0) //if targetWord[i] is an exponent of x
            for (int j = 1; j <= targetWord[i]; j++)
            {
                pcurrentNode = buildXprod(pcurrentNode);
                path.push_back(pcurrentNode);
            }
        else            //if targetWord[i] is an exponent of y
            for (int j = 1; j <= targetWord[i]; j++)
            {
                pcurrentNode = buildYprod(pcurrentNode);
                path.push_back(pcurrentNode);
            }
    }

    //now build the last exponent, up to the last product. since using buildXprod, it's safe
    //to "build" the targetWord, but we won't do it anyway
    if (i % 2 == 0)
    {
        for (int j = 1; j < targetWord[i]; j++)
        {
            pcurrentNode = buildXprod(pcurrentNode);
            path.push_back(pcurrentNode);
        }

        //link final
        setXedge(pcurrentNode, ptargetNode);
    }
    else            //if targetWord[i] is an exponent of y
    {
        for (int j = 1; j < targetWord[i]; j++)
        {
//.........这里部分代码省略.........
开发者ID:clamheart,项目名称:BGG,代码行数:101,代码来源:graph3.cpp

示例2: preservePath

//Set nodes in path to OPEN
void Graph::preservePath(std::list<Node>::iterator pbaseNode, std::list<Node>::iterator ptargetNode)
{
    //make sure iterators are valid
    std::list<Node>::iterator pnull = std::list<Node>::iterator(NULL);
    if (pbaseNode == pnull || ptargetNode == pnull)
    {
        //std::cout << "\nNULL ITERATORS PASSED TO preservePath()\n";
        return;
    }

    std::vector<short> baseWord = pbaseNode->getElemName();
    std::vector<short> targetWord = ptargetNode->getElemName();

    //target word must be longer than or equal length as base word
    if (targetWord.size() < baseWord.size())
    {
        //std::cout << "\nPRESERVE PATH BAD RETURN1\n";
        return;
    }
    //should never touch the identity; this is a special case which is handled in initial step
    if (baseWord[0] == 0 || targetWord[0] == 0)
    {
        //std::cout << "\nPRESERVE PATH BAD RETURN2\n";
        return;
    }
    //if words are identical there's nothing to do
    if (baseWord == targetWord)
    {
        //std::cout << "\nPRESERVE PATH BAD RETURN3\n";
        return;
    }
        //return;

    //At this point we know the nodes exist, their words have appropriate sizes, they're not the identity,
    //and they're not equal. But we could still have the problem that the base word is not contained
    //in the leftmost portion of the target word, so we check for that.
    bool baseContained = true;
    int i;
    for (i = 0; i < baseWord.size() - 1; i++)  //up until the last letter, each exponent identical
        if (baseWord[i] != targetWord[i])
            baseContained = false;
    if (baseWord[i] > targetWord[i])  //on the last letter, the exponent in base may be less or equal
        baseContained = false;
    if (baseContained == false)
    {
        std::cout << "\nPRESERVE PATH not contained:\n";
        pbaseNode->printWord();
        std::cout << "\n";
        ptargetNode->printWord();
        std::cout << "\n";
        return;
    }

    //nodes have been checked


    std::list<Node>::iterator psetNode = ptargetNode;
    while (targetWord.size() != baseWord.size()) //stop at last exponent of baseWord
    {
        int i = targetWord.size() - 1;  //always index of last exponent in targetWord
        int exp = targetWord[i];  //last exponent on targetWord
        while (exp > 0)
        {
            targetWord[i] = exp;
            psetNode = searchNodes(&targetWord);
            if (psetNode == std::list<Node>::iterator(NULL))
            {
                std::cout << "\nAttempt to set node via null iterator in preservePath()\n";
                return;
            }
            if (psetNode->getNodeType() != Node::TEMP && psetNode != ptargetNode)
            {
                //it's okay to hit a preserved node, this means the nodes before this one will also
                //be preserved
                return;
            }
            psetNode->setNodeType(Node::OPEN);
            exp--;
        }
        targetWord.pop_back(); //remove exponent just cleared
    }
    int d = targetWord.size() - 1;
    if (targetWord[d] == baseWord[d])
    {
        if(pbaseNode->isOpen())
            psetNode->setNodeType(Node::OPEN);
        else psetNode->setNodeType(Node::CLOSED);
        return;
    }
    int exp = targetWord[d];  //last exponent on targetWord
    while (exp > baseWord[d])
    {
        targetWord[d] = exp;
        psetNode = searchNodes(&targetWord);
        if (psetNode == std::list<Node>::iterator(NULL))
        {
            std::cout << "\nAttempt to set node via null iterator in preservePath()\n";
            return;
        }
//.........这里部分代码省略.........
开发者ID:clamheart,项目名称:BGG,代码行数:101,代码来源:graph3.cpp


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