main() { struct list *root=NULL; int choice,pos,val; printf("MENU : \n1.create\n2.insert at begin\n3.insert at end\n4.insert at pos\n5.delete at begin\n6.delete at end\n7.delete at pos\n8.display\n9.exit\n10.nth node from last\n"); while(1) { printf("enter ur choice\n"); scanf("%d",&choice); switch(choice) { case 1: if(root!=NULL) printf("list is already created\n"); else { printf("enter value\n"); scanf("%d",&val); root=insert_at_end(root,val); printf("list is created\n"); } break; case 2: printf("enter value\n"); scanf("%d",&val); root=insert_at_begin(root,val); printf("value is inserted at begin\n"); break; case 3: printf("enter the value\n"); scanf("%d",&val); root=insert_at_end(root,val); printf("val is inserted at end\n"); break; case 4: printf("enter val\n"); scanf("%d",&val); printf("enter pos\n"); scanf("%d",&pos); root=insert_at_pos(root,val,pos); break; case 5: if(root==NULL) printf("nothing to delete\n"); else { root=delete_at_begin(root); printf("node is deleted at begin\n"); } break; case 6: if(root==NULL) printf("nothing to delete\n"); else { root=delete_at_end(root); printf("node is deleted at end\n"); } break; case 7: printf("enter pos\n"); scanf("%d",&pos); root=delete_at_pos(root,pos); break; case 8: display(root); break; case 9: exit(0); case 10: printf("enter n value \n"); scanf("%d", &pos); val=nth_node_val_from_last(root,pos); if(val!=777) printf("the nth node value from last is %d\n",val); break; } } }
int main() { int choice; start=NULL; while(1){ clearTerminal(); printf("1.Create Train\n"); printf("2.Display Train\n"); printf("3.Insert Bogie into Train\n"); printf("4.Remove Bogie from Train\n"); printf("5.Search Bogie into Train\n"); printf("6.Reverse the Train\n"); printf("7.Exit"); printf("\nEnter Your choice : "); fflush(stdin); scanf("%d",&choice); clearTerminal(); switch(choice) { case 1: create_Train(); break; case 2: display(); break; case 3: if(start!=NULL) { clearTerminal(); printf("1.Insert at begining of the Train\n"); printf("2.Insert at End of the Train\n"); printf("3.Insert at Position of the Train\n"); printf("4.Back To Previous Menu.\n"); printf("\nEnter Your choice : "); fflush(stdin); scanf("%d",&choice); int bg_no; switch(choice) { case 1: insert_at_beg(getInput()); printf("Bogie Insert at begining of the Train.\n"); break; case 2: insert_at_end(getInput()); printf("Bogie Insert at end of the Train.\n"); break; case 3: insert_at_pos(); break; case 4: break; default: printf("\a\a\aInvalid Input!!!\n"); } } else { printf("\a\a\aThere no train is build yet!!!\n"); } break; case 7: exit(1); default: printf("\a\a\aInvalid Input!!!\n"); } printf("Press [Enter] key to continue.\n"); getchar(); getchar(); } return 3; }