Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main()
- {
- node_id* root_id;
- node_id* root_name;
- root_name = NULL;
- root_id = NULL;
- printf("-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\n\n");
- printf("choose:\n");
- printf("1- insert data\n");
- printf("2- write file to tree\n3- print preorder by id\n");
- printf("4- print preorder by name\n5- print post order by id\n");
- printf("6- print post order by name\n7- inorder by id\n");
- printf("8- print inorder by name\n");
- printf("9- delete by id\n10- delete by name\n");
- printf("11- search by name\n12- search by id\n");
- printf("13- read file to tree\n14- quit\n\n");
- int command;
- char co[20];
- char name[40];
- int id;
- char c;
- printf("Enter command: ");
- scanf(" %s", co);
- command = atoi(co);
- do
- {
- if(command<1 || command>14)
- {
- system("cls");
- printf("enter valid number\n\n");
- }
- else
- switch (command)
- {
- case 14:
- {
- system("cls");
- printf("THANK YOU!\n\n");
- printf("Ahmad Omar 2715 & Ahmad Abdulaziz 2210\n\n");
- exit(0);
- break;
- }
- case 1:
- {
- system("cls");
- printf("Enter name: ");
- while((c= getchar()) != '\n' && c != EOF);
- gets(name);
- printf("Enter id: ");
- scanf("%d", &id);
- insert(&root_id, &root_name, id, name);
- break;
- }
- case 2:
- {
- system("cls");
- char file_name[50];
- printf("Enter file name: ");
- scanf("%s", file_name);
- FILE* file = fopen(file_name, "w");
- write_tree_to_file(root_id, file);
- fclose(file);
- break;
- break;
- }
- case 3:
- {
- system("cls");
- print_preorder(root_id,0);
- break;
- }
- case 4:
- {
- system("cls");
- print_preorder(root_name,0);
- break;
- }
- case 5:
- {
- system("cls");
- print_postorder(root_id,0);
- break;
- }
- case 6:
- {
- system("cls");
- print_postorder(root_name,0);
- break;
- }
- case 7:
- {
- system("cls");
- print_inorder(root_id,0);
- break;
- }
- case 8:
- {
- system("cls");
- print_inorder(root_name,0);
- break;
- }
- case 9:
- {
- system("cls");
- printf("Enter id: ");
- scanf("%d", &id);
- node_id* temp = search_id(&root_id, id);
- if (temp != NULL)
- {
- strcpy(name, temp->name);
- }
- else
- printf("NOT FOUND.\n\n");
- root_id = delete_id(root_id, id);
- root_name = delete_name(root_name,name);
- break;
- }
- case 10:
- {
- system("cls");
- printf("Enter name: ");
- while((c= getchar()) != '\n' && c != EOF);
- gets(name);
- node_id* temp = search_name(&root_name, name);
- if (temp != NULL)
- {
- id = temp->id;
- }
- else
- printf("NOT FOUND.\n\n");
- root_id = delete_id(root_id, id);
- root_name = delete_name(root_name, name);
- break;
- }
- case 11:
- {
- system("cls");
- printf("Enter name: ");
- while((c= getchar()) != '\n' && c != EOF);
- gets(name);
- search_name_2(&root_name, name);
- break;
- }
- case 12:
- {
- system("cls");
- printf("Enter id: ");
- scanf("%d", &id);
- search_id_2(&root_id, id);
- break;
- }
- case 13:
- {
- system("cls");
- char file_name[50];
- printf("Enter file name: ");
- scanf("%s", file_name);
- reed_file_to_tree(&root_id, &root_name, file_name);
- break;
- }
- case 15:
- {
- }
- default:
- {
- break;
- }
- }
- printf("-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\n\n");
- printf("choose:\n");
- printf("1- insert data\n");
- printf("2- write file to tree\n3- print preorder by id\n");
- printf("4- print preorder by name\n5- print post order by id\n");
- printf("6- print post order by name\n7- inorder by id\n");
- printf("8- print inorder by name\n");
- printf("9- delete by id\n10- delete by name\n");
- printf("11- search by name\n12- search by id\n");
- printf("13- read file to tree\n14- quit\n\n");
- printf("Enter command: ");
- scanf(" %s", co);
- command = atoi(co);
- }
- while (command != ~(1<<31));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement