这个项目的价值是陈旧的吗?

时间:2015-04-12 00:56:28

标签: c linked-list staleobjectstate

我在实现或创建列表之后遇到链表的问题,然后将指向列表的指针发送到另一个实现或创建二进制搜索树的函数。当从函数返回列表时,列表不再存在。我在调试时收到一条消息说"由于在评估时发生的问题,该项的值是陈旧的。谢谢您的帮助。这是一些代码。

void menuJosephZanini()
{
    int option;
    PolyListAddrJosephZanini left =
        (PolyListJosephZanini) malloc(sizeof(PNodeJosephZanini));
    PolyListAddrJosephZanini right =
        (PolyListJosephZanini) malloc(sizeof(PNodeJosephZanini));
    PolyListAddrJosephZanini result =
        (PolyListJosephZanini) malloc(sizeof(PNodeJosephZanini));
    ExBstRootAddrJosephZanini leftTree =
        (ExBstRootJosephZanini) malloc(sizeof(ExBstNodeJosephZanini));
    ExBstRootAddrJosephZanini rightTree =
        (ExBstRootJosephZanini) malloc(sizeof(ExBstNodeJosephZanini));

    *(left) = 0;
    *(right) = 0;
    *(result) = 0;
    *(leftTree) = 0;
    *(rightTree) = 0;


    do {
        printf("\n\n******************************"\
            "\n*    POLYNOMIAL OPERATIONS   *"\
            "\n* 1. Creating polynomials    *"\
            "\n* 2. Adding polynomials      *"\
            "\n* 3. Multiplying polynomials *"\
            "\n* 4. Displaying polynomials  *"\
            "\n* 5. Clearing polynomials    *"\
            "\n* 6. Quit                    *"\
            "\n******************************"
            "\nSelect the option(1 through 6) : ");
        scanf("%d", &option);
        switch (option) {
        case 1:
            createPolyMenuJosephZanini(left, right, leftTree,
                rightTree);
            break;
        case 2:
            break;
        case 3:
            break;
        case 4:
            displayPolyJosephZanini(left, right, result);
            break;
        case 5:
            break;
        case 6:
            break;
        default:
            printf("\n    You should not be in this class!");
        }
    } while (option != 6);

    return;
}

void createPolyMenuJosephZanini(PolyListAddrJosephZanini left,
    PolyListAddrJosephZanini right, ExBstRootAddrJosephZanini leftTree,
    ExBstRootAddrJosephZanini rightTree)
{
    int option;

    do {
        printf("\n\n  ****************************"\
            "\n  *    CREATE POLYNOMIALS    *"\
            "\n  * 1. createLeftPolyJZ()    *"\
            "\n  * 2. createRightPolyJZ()   *"\
            "\n  * 3. displayCurrentPolys() *"\
            "\n  * 4. Quit                  *"\
            "\n  ****************************"\
            "\n  Enter option 1, 2, 3 or 4 : ");
        scanf("%d", &option);
        switch (option) {
        case 1:
            createLeftPolyJZ(left);
            *(leftTree) = createExBstJosephZanini(left); //problem at this line
            break;
        case 2:
            createRightPolyJZ(right);
            *(rightTree) = createExBstJosephZanini(right);
            break;
        case 3:
            displayCurrentPolyJZ(left, right);
            break;
        case 4:
            break;
        default:
            printf("\n    You should not be in this class!");
        }
    } while (option != 4);

    return;
}

void createPolyListJosephZanini(PNodeAddrJosephZanini* head)
{
     PNodeAddrJosephZanini temp;
     int option;

     *(head) = createPolyNode01();
     temp = *(head);

     do {
         printf("\n\n      Would you like to insert another Polynomial 
         term?");                                      
        "\n        1. yes"\
        "\n        2. no"\
        "\n        Enter option 1 or 2 : ");
        scanf("%d", &option);

        switch (option) {
        case 1 :
            temp->next = createPolyNode01();
            temp = temp->next;
            break;
        case 2 :
            printf("\n\n          Display from main menu to see created Polynomial.");
            break;
        default: 
            printf("\n\n          Not an option!!");
        } 
    } while (option != 2);

    return;
}


PNodeAddrJosephZanini createPolyNode01()
{
    PNodeAddrJosephZanini nPtr =
        (PNodeAddrJosephZanini) malloc(sizeof(PNodeJosephZanini));

    nPtr->termAddr = createTermJosephZanini();

    nPtr->next = 0;

    return nPtr;
}

抱歉,如果格式错误。我是新来发布在这个网站上,但我迫切需要帮助。

0 个答案:

没有答案