Advertisement
ahmad_zizo

MENU

May 29th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1.  
  2.  
  3. int main()
  4. {
  5. node_id* root_id;
  6. node_id* root_name;
  7.  
  8.  
  9. root_name = NULL;
  10. root_id = NULL;
  11. printf("-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\n\n");
  12. printf("choose:\n");
  13. printf("1- insert data\n");
  14. printf("2- write file to tree\n3- print preorder by id\n");
  15. printf("4- print preorder by name\n5- print post order by id\n");
  16. printf("6- print post order by name\n7- inorder by id\n");
  17. printf("8- print inorder by name\n");
  18. printf("9- delete by id\n10- delete by name\n");
  19. printf("11- search by name\n12- search by id\n");
  20. printf("13- read file to tree\n14- quit\n\n");
  21.  
  22.  
  23. int command;
  24. char co[20];
  25.  
  26. char name[40];
  27. int id;
  28. char c;
  29. printf("Enter command: ");
  30. scanf(" %s", co);
  31. command = atoi(co);
  32.  
  33. do
  34. {
  35. if(command<1 || command>14)
  36. {
  37. system("cls");
  38. printf("enter valid number\n\n");
  39. }
  40. else
  41. switch (command)
  42. {
  43. case 14:
  44. {
  45. system("cls");
  46. printf("THANK YOU!\n\n");
  47. printf("Ahmad Omar 2715 & Ahmad Abdulaziz 2210\n\n");
  48. exit(0);
  49. break;
  50. }
  51. case 1:
  52. {
  53. system("cls");
  54. printf("Enter name: ");
  55. while((c= getchar()) != '\n' && c != EOF);
  56. gets(name);
  57. printf("Enter id: ");
  58. scanf("%d", &id);
  59.  
  60. insert(&root_id, &root_name, id, name);
  61. break;
  62. }
  63.  
  64.  
  65. case 2:
  66. {
  67. system("cls");
  68. char file_name[50];
  69. printf("Enter file name: ");
  70. scanf("%s", file_name);
  71. FILE* file = fopen(file_name, "w");
  72. write_tree_to_file(root_id, file);
  73. fclose(file);
  74.  
  75. break;
  76. break;
  77. }
  78.  
  79. case 3:
  80. {
  81. system("cls");
  82. print_preorder(root_id,0);
  83. break;
  84. }
  85. case 4:
  86. {
  87. system("cls");
  88. print_preorder(root_name,0);
  89. break;
  90. }
  91.  
  92. case 5:
  93. {
  94. system("cls");
  95. print_postorder(root_id,0);
  96. break;
  97. }
  98. case 6:
  99. {
  100. system("cls");
  101. print_postorder(root_name,0);
  102. break;
  103. }
  104. case 7:
  105. {
  106. system("cls");
  107. print_inorder(root_id,0);
  108. break;
  109. }
  110. case 8:
  111. {
  112. system("cls");
  113. print_inorder(root_name,0);
  114. break;
  115. }
  116. case 9:
  117. {
  118. system("cls");
  119. printf("Enter id: ");
  120. scanf("%d", &id);
  121. node_id* temp = search_id(&root_id, id);
  122. if (temp != NULL)
  123. {
  124. strcpy(name, temp->name);
  125. }
  126. else
  127. printf("NOT FOUND.\n\n");
  128. root_id = delete_id(root_id, id);
  129. root_name = delete_name(root_name,name);
  130. break;
  131. }
  132. case 10:
  133. {
  134. system("cls");
  135. printf("Enter name: ");
  136. while((c= getchar()) != '\n' && c != EOF);
  137. gets(name);
  138.  
  139. node_id* temp = search_name(&root_name, name);
  140. if (temp != NULL)
  141. {
  142. id = temp->id;
  143. }
  144. else
  145. printf("NOT FOUND.\n\n");
  146. root_id = delete_id(root_id, id);
  147. root_name = delete_name(root_name, name);
  148. break;
  149. }
  150. case 11:
  151. {
  152. system("cls");
  153. printf("Enter name: ");
  154. while((c= getchar()) != '\n' && c != EOF);
  155. gets(name);
  156. search_name_2(&root_name, name);
  157. break;
  158. }
  159. case 12:
  160. {
  161. system("cls");
  162. printf("Enter id: ");
  163. scanf("%d", &id);
  164. search_id_2(&root_id, id);
  165. break;
  166. }
  167. case 13:
  168. {
  169. system("cls");
  170. char file_name[50];
  171. printf("Enter file name: ");
  172. scanf("%s", file_name);
  173. reed_file_to_tree(&root_id, &root_name, file_name);
  174.  
  175. break;
  176. }
  177. case 15:
  178. {
  179.  
  180. }
  181. default:
  182. {
  183. break;
  184. }
  185. }
  186.  
  187. printf("-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\n\n");
  188. printf("choose:\n");
  189. printf("1- insert data\n");
  190. printf("2- write file to tree\n3- print preorder by id\n");
  191. printf("4- print preorder by name\n5- print post order by id\n");
  192. printf("6- print post order by name\n7- inorder by id\n");
  193. printf("8- print inorder by name\n");
  194. printf("9- delete by id\n10- delete by name\n");
  195. printf("11- search by name\n12- search by id\n");
  196. printf("13- read file to tree\n14- quit\n\n");
  197. printf("Enter command: ");
  198. scanf(" %s", co);
  199. command = atoi(co);
  200. }
  201. while (command != ~(1<<31));
  202.  
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement