电话簿使用双链表

时间:2016-10-24 16:41:18

标签: c++ data-structures linked-list

问题是程序在第一选择时运行良好但是它开始重复而不需要选择并进入addNode或SearchNode函数

list *newList = new list;

int choice = 0;
while (choice != 3)
{
    printf("What would you like to do?\n");
    printf("1 - Insert something in the phonebook?\n");
    printf("2 - Search something from the phonebook?\n");
    printf("3 - Nothing at all\n");
    printf("Enter 1 through 5: ");
    scanf_s("%d", &choice);


    switch (choice) {
    case 1:
        newList->addNode();
        break;
    case 2:
        newList->searchNode();
        break;
    default:
        printf("\nThank you for using the phonebook\n");
    }
    choice = 0;
}

2 个答案:

答案 0 :(得分:1)

在循环结束时将<script type="application/javascript" scr="scripts/PeopleTableViewModel.js"></script> 设置为0 然后代码检查循环顶部的值 循环顶部的值为0,不等于3,因此循环继续。

答案 1 :(得分:0)

如果您仍想保持&#39; choice = 0;&#39;在while循环中你可以使用类似的东西:

如果(选择!= 3) 选择= 0;

希望这有帮助!