int menu_body(char ch,int choice) { static int flag; int data,result; switch (ch) { case ESC: { clrscr(); flag=1; } break; case ENTER: { switch(choice) { case 0: { clrscr(); gotoxy(0,0); /*Please Add your function here*/ puts("Enter the new element to list"); fflush(stdout); scanf("%d",&data); result=insert_node_sll(&start,data); (result==1)?puts("Element has been added"):puts("Faild to enter the element"); puts("Enter any key to back to menu"); getch(); } break; case 1: { clrscr(); gotoxy(0,0); /*Please Add your function here*/ print_sll (start); puts("Enter any key to back to menu"); getch(); } break; case 2: { clrscr(); gotoxy(0,0); /*Please Add your function here*/ puts("Enter an element to find it"); fflush(stdout); scanf("%d",&data); result=find_sll (start ,data); (result==1)?printf("Element %d has been found\n",data) :printf("Element %d is not presented in list\n",data); puts("Enter any key to back to menu"); getch(); break; } break; case 3: clrscr(); gotoxy(0,0); /*Please Add your function here*/ puts("Enter an element to delete"); fflush(stdout); scanf("%d",&data); result=delete_sll(&start,data); (result==1)?puts("Element has been deleted"):puts("Element has not been found"); puts("Enter any key to back to menu"); getch(); break; case 4: clrscr(); gotoxy(0,0); /*Please Add your function here*/ result=get_count_sll(start); printf("Number of elements in list is %d\n",result); puts("Enter any key to back to menu"); getch(); break; case 5: clrscr(); gotoxy(0,0); /*Please Add your function here*/ free_list(&start); getch(); break; case 6: clrscr(); gotoxy(0,0); /*Please Add your function here*/ reverse_sll(&start); print_sll (start); getch(); break; case 7: flag=1; break; } } } return(flag); }
/* Story 5: delete_sll */ void test5(void) { list test_list = NULL;; printf("Testing story 5: delete_sll\n"); delete_sll(test_list, 1); print_list("Failed deleting first position from empty list", test_list); test_list = init_sll(test_list); print_list("List initialized to", test_list); print_list("Deleted position 0", delete_sll(test_list, 0)); test_list = init_sll(test_list); print_list("Deleted position 1", delete_sll(test_list, 1)); test_list = init_sll(test_list); print_list("Deleted position 2", delete_sll(test_list, 2)); test_list = init_sll(test_list); print_list("Failed to delete position 3", delete_sll(test_list, 3)); test_list = delete_sll(test_list, 0); print_list("Permently deleted position 0", test_list); test_list = delete_sll(test_list, 0); print_list("Permently deleted position 0", test_list); test_list = delete_sll(test_list, 0); print_list("Permently deleted position 0", test_list); test_list = init_sll(test_list); print_list("List re-initialized to", test_list); test_list = delete_sll(test_list, 2); print_list("Permently deleted position 2", test_list); test_list = delete_sll(test_list, 1); print_list("Permently deleted position 1", test_list); test_list = delete_sll(test_list, 0); print_list("Permently deleted position 0", test_list); }