如何回到之前的Switch case主选项? [等候接听]

当用户选择'0'时,我需要从 case 4 中的无限循环返回到我之前的开关案例 . 我怎样才能做到这一点?

#include <iostream> 
using namespace std;

struct Node {
    int data;
    Node* next;
}* head = NULL;

int main()
{
    Node *temp, *x;
    int flag;

    while (1) {
        cout << "Main Menu\n1. Insert Node\n2. Show the list\n3. Search Node\n4. Update\n5. Delete Node \n6. Exit\n";
        int option;
        cout << "Choice your option" << endl;
        cin >> option;

        switch (option) {
        case 1:
            if (head == NULL) {
                temp = new Node;
                cin >> temp->data;
                temp->next = NULL;
                head = temp;
                x = head;
            }
            else {
                temp = new Node;
                cin >> temp->data;
                temp->next = NULL;
                x->next = temp;
                x = x->next;
            }
            break;

        case 2:
            cout << "List Showing Blew:" << endl;
            x = head;
            while (x != NULL) {
                cout << x->data << " ";
                x = x->next;
            }
            cout << endl;
            break;

        case 3:
            cout << "Which value do you want to search:" << endl;
            int find;
            cin >> find;
            x = head;
            flag = 0;
            while (x != NULL) {
                if (x->data == find) {
                    flag = 1;
                }
                x = x->next;
            }
            if (flag == 1) {
                cout << "Value Found" << endl;
            }
            else {
                cout << "Value Not Found" << endl;
            }
            break;

        case 4:
            cout << "Update Node" << endl;
            while (1) {
                cout << "Update Menu\n1. Sort Node As Ascending Order\n2. Sort Node As Descending Order\n0. Exit\nChoice your option:";
                int updateOption;
                cin >> updateOption;
                switch (updateOption) {
                case 1:
                    cout << "Ascending Order" << endl;
                    break;
                case 2:
                    cout << "Descending Order" << endl;
                    break;
                case 0:
                    switch (option = 1)
                        ;
                    break;
                default:
                    cout << "Invalid Input!!!" << endl;
                    break;
                }
            }

            break;
        case 5:
            cout << "Case 4" << endl;
            break;
        case 6:
            cout << "Case 5" << endl;
            break;
        case 7:
            cout << "Case 6" << endl;
            break;
        default:
            cout << "Invalid grade" << endl;
            break;
        }
    }
    return 0;
}

回答(0)