c++ - 使用双链表的电话簿

标签 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;
}

最佳答案

在循环结束时将 choice 设置为 0。
然后代码会去检查循环顶部的值。
循环顶部的值为 0,不等于 3,因此循环继续。

关于c++ - 使用双链表的电话簿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40223401/

相关文章:

python - Python列表是否与我的数据结构和算法教科书定义的列表相同?

java - FOR EACH 循环中的并行迭代

c++ - 面试测试中使用的LinkedList

c++ - 嵌入式编程中宏值之间的比较是否不好?

c++ - 使用 libsndfile 处理大文件

c# - 使用 DllImport 将非托管 dll 加载到托管应用程序中

algorithm - 使用集合生成子字符串

c++ - 如何将按钮锚定到小部件?

c++ - 如何在链表中搜索结构对象

java - 将操作数<T>转换为整数