" MENU"在用户有机会输入选择之前,对链表程序退出执行操作

时间:2017-08-11 18:52:01

标签: c linked-list switch-statement

我正在创建一个菜单来对链接列表执行多个操作,但是一旦我要求用户为链接列表输入MAXSIZE,程序就会调出" MENU"询问用户他们想做什么,然后程序在继续语句之后立即退出,因为我不在循环内。
  int main()

{

/* Start with the empty list */

struct Node* head = NULL;


int MAXSIZE;
printf("Welcome to the Menu\n");
printf("To begin please select a MAXSIZE for the linked list\n");
scanf("%d",&MAXSIZE);
printf("A. Priority queue\n");
printf("B. Append list\n");
printf("C. Eliminate from list\n");
printf("D. Reverse the linked list\n");
printf("Please enter your choice: ");
char var;
scanf("%c",&var);

int j=1;

if(j==1){

switch(var){

        case 'C' :
        case 'c':
        printf("Created Linked List: ");
        int h;

            printList(head);

            printf("\nPlease enter number to eliminate");
            scanf("%d",&h);


                    eliminateFromList(head, h);

                    printf("\nLinked List after Deletion of %d:\n",h);

                    printList(head);
                    printf("\n");

                break;
    case 'B':
    case 'b':;

        int temp2;
        int temp1;
        for(int i =0; i<MAXSIZE; i++){
            printf("Please Enter a value to populate array along with a priority between 1 and 10");
            scanf("%d",&temp1);
            scanf("%d",&temp2);
            push(&head,temp1,temp2);
        }

        break;

    case 'A':
    case 'a':
        printf("Hello world\n");
        break;

    case 'D':
    case 'd':
        printf("Hello world\n");
        break;

}
}
}

0 个答案:

没有答案