Advertisement
anhlocpr

aa

Sep 5th, 2015
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.71 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include <windows.h>
  4. #include <graphics.h>
  5. #define bool int
  6.  
  7. int i = 500;
  8. struct tNode
  9. {
  10. char data;
  11. struct tNode* left;
  12. struct tNode* right;
  13. };
  14. struct sNode
  15. {
  16. struct tNode *t;
  17. struct sNode *next;
  18. };
  19.  
  20. void push(struct sNode** top_ref, struct tNode *t);
  21. struct tNode *pop(struct sNode** top_ref);
  22. bool isEmpty(struct sNode *top);
  23.  
  24.  
  25.  
  26. void push(struct sNode** top_ref, struct tNode *t)
  27. {
  28.  
  29. struct sNode* new_tNode =
  30. (struct sNode*) malloc(sizeof(struct sNode));
  31.  
  32. if(new_tNode == NULL)
  33. {
  34. printf("Stack Overflow \n");
  35. getchar();
  36. exit(0);
  37. }
  38.  
  39. new_tNode->t = t;
  40.  
  41. new_tNode->next = (*top_ref);
  42.  
  43. (*top_ref) = new_tNode;
  44. }
  45.  
  46. bool isEmpty(struct sNode *top)
  47. {
  48. return (top == NULL)? 1 : 0;
  49. }
  50.  
  51.  
  52. struct tNode *pop(struct sNode** top_ref)
  53. {
  54. struct tNode *res;
  55. struct sNode *top;
  56.  
  57.  
  58. if(isEmpty(*top_ref))
  59. {
  60. printf("Stack Underflow \n");
  61. getchar();
  62. exit(0);
  63. }
  64. else
  65. {
  66. top = *top_ref;
  67. res = top->t;
  68. *top_ref = top->next;
  69. free(top);
  70. return res;
  71. }
  72. }
  73.  
  74. struct tNode* newtNode(char data)
  75. {
  76. struct tNode* tNode = (struct tNode*)
  77. malloc(sizeof(struct tNode));
  78. tNode->data = data;
  79. tNode->left = NULL;
  80. tNode->right = NULL;
  81.  
  82. return(tNode);
  83. }
  84. int Ve_HT(int x, int y, int r,int color)
  85. {
  86. setcolor(color);
  87. circle(x,y,r);
  88. }
  89. int Ve_DT(int x1, int y1, int x2, int y2, int color)
  90. {
  91. setcolor(color);
  92. line(x1,y1,x2,y2);
  93. }
  94. int In_Text(int x, int y, char *s, int color)
  95. {
  96. setcolor(color);
  97. outtextxy(x,y,s);
  98. }
  99. void To_mau(int x, int y, int r,int m, int n, int color,char *k)
  100. {
  101. setcolor(color);
  102. circle(x,y,r);
  103. settextstyle(0,HORIZ_DIR,3);
  104. In_Text(x,y+5,k,color);
  105.  
  106. Beep(i,500);
  107. i+=50;
  108. setcolor(color);
  109. Ve_HT(m,n,30, color);
  110. settextstyle(0,HORIZ_DIR,3);
  111. settextjustify(1,1);
  112. In_Text(m,n+5,k,color);
  113. delay(1500);
  114. }
  115. void inOrder(struct tNode *root)
  116. {
  117. /* set current to root of binary tree */
  118. struct tNode *current = root;
  119. struct sNode *s = NULL; /* Initialize stack s */
  120. bool done = 0;
  121. int count = 0;
  122. char s1[1];
  123. char* ret = NULL;
  124. char c[11];
  125. while (!done)
  126. {
  127.  
  128. if(current != NULL)
  129. {
  130.  
  131. push(&s, current);
  132. current = current->left;
  133. }
  134. else
  135. {
  136. if (!isEmpty(s))
  137. {
  138. current = pop(&s);
  139. strncpy(s1,&current->data ,1);
  140. ret = new char[1];
  141. ret[0] = s1[0];
  142. count++;
  143. switch (count)
  144. {
  145. case 1:
  146. To_mau(500,600,25,400,280,RED,ret);
  147. break;
  148. case 2:
  149. To_mau(580,600,25,500,450,BLUE,ret);
  150. break;
  151. case 3:
  152. To_mau(660,600,25,500,120,YELLOW,ret);
  153. break;
  154. case 4:
  155. To_mau(740,600,25,600,280,GREEN,ret);
  156. break;
  157. case 5:
  158. To_mau(820,600,25,683,50,CYAN,ret);
  159. break;
  160. case 6:
  161. To_mau(900,600,25,766,280,LIGHTRED,ret);
  162. break;
  163. case 7:
  164. To_mau(980,600,25,866,120,LIGHTBLUE,ret);
  165. break;
  166. case 8:
  167. To_mau(1060,600,25,966,280,LIGHTMAGENTA,ret);
  168. break;
  169. case 9:
  170. To_mau(1140,600,25,1066,450,DARKGRAY,ret);
  171. break;
  172. }
  173. current = current->right;
  174. }
  175. else
  176. done = 1;
  177. }
  178. }
  179.  
  180. }
  181.  
  182. int main()
  183. {
  184.  
  185. struct tNode *root = NULL;
  186. root = newtNode('A');
  187. root->left = newtNode('C');
  188. root->right = newtNode('B');
  189. root->left->left = newtNode('G');
  190. root->left->right = newtNode('F');
  191. root->left->left->right = newtNode('I');
  192. root->right->left = newtNode('E');
  193. root->right->right = newtNode('D');
  194. root->right->right->right = newtNode('H');;
  195. initwindow(1366,768);
  196.  
  197. Ve_HT(683,50,30, WHITE); //Muc 1
  198. delay(500);
  199. settextstyle(0,HORIZ_DIR,3);
  200. settextjustify(1,1);
  201. In_Text(683,55,"A",WHITE);
  202.  
  203. Ve_DT(652,50,526,105, WHITE);
  204. Ve_DT(712,50,840,105, WHITE);
  205.  
  206. Ve_HT(500,120,30, WHITE);//Muc 2
  207. delay(500);
  208. settextstyle(0,HORIZ_DIR,3);
  209. settextjustify(1,1);
  210. In_Text(500,125,"C",WHITE);
  211.  
  212. Ve_HT(866,120,30, WHITE);
  213. delay(500);
  214. settextstyle(0,HORIZ_DIR,3);
  215. settextjustify(1,1);
  216. In_Text(866,125,"B",WHITE);
  217.  
  218. Ve_DT(475,135,415,255, WHITE);
  219. Ve_DT(525,135,585,255, WHITE);
  220. Ve_DT(840,135,776,255, WHITE);
  221. Ve_DT(892,135,950,255, WHITE);
  222.  
  223. Ve_HT(400,280,30, WHITE);//Muc 3
  224. delay(500);
  225. settextstyle(0,HORIZ_DIR,3);
  226. settextjustify(1,1);
  227. In_Text(400,285,"G",WHITE);
  228.  
  229. Ve_HT(600,280,30, WHITE);
  230. delay(500);
  231. settextstyle(0,HORIZ_DIR,3);
  232. settextjustify(1,1);
  233. In_Text(600,285,"F",WHITE);
  234.  
  235. Ve_HT(766,280,30, WHITE);
  236. delay(500);
  237. settextstyle(0,HORIZ_DIR,3);
  238. settextjustify(1,1);
  239. In_Text(766,285,"E",WHITE);
  240.  
  241. Ve_HT(966,280,30, WHITE);
  242. delay(500);
  243. settextstyle(0,HORIZ_DIR,3);
  244. settextjustify(1,1);
  245. In_Text(966,285,"D",WHITE);
  246.  
  247. Ve_DT(375,295,515,425, WHITE);
  248. Ve_DT(990,295,1055,425, WHITE);
  249.  
  250. Ve_HT(500,450,30, WHITE);//Muc 4
  251. delay(500);
  252. settextstyle(0,HORIZ_DIR,3);
  253. settextjustify(1,1);
  254. settextstyle(0,HORIZ_DIR,3);
  255. In_Text(500,455,"I",WHITE);
  256.  
  257. Ve_HT(1066,450,30, WHITE);
  258. settextjustify(1,1);
  259. In_Text(1066,455,"H",WHITE);
  260.  
  261. settextstyle(0,HORIZ_DIR,2);
  262. In_Text(300,600,"Thu tu duyet giua la: ", WHITE);
  263.  
  264. system("pause");
  265. inOrder(root);
  266. getch();
  267. return 0;
  268. closegraph();
  269. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement