Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include <windows.h>
- #include <graphics.h>
- #define bool int
- int i = 500;
- struct tNode
- {
- char data;
- struct tNode* left;
- struct tNode* right;
- };
- struct sNode
- {
- struct tNode *t;
- struct sNode *next;
- };
- void push(struct sNode** top_ref, struct tNode *t);
- struct tNode *pop(struct sNode** top_ref);
- bool isEmpty(struct sNode *top);
- void push(struct sNode** top_ref, struct tNode *t)
- {
- struct sNode* new_tNode =
- (struct sNode*) malloc(sizeof(struct sNode));
- if(new_tNode == NULL)
- {
- printf("Stack Overflow \n");
- getchar();
- exit(0);
- }
- new_tNode->t = t;
- new_tNode->next = (*top_ref);
- (*top_ref) = new_tNode;
- }
- bool isEmpty(struct sNode *top)
- {
- return (top == NULL)? 1 : 0;
- }
- struct tNode *pop(struct sNode** top_ref)
- {
- struct tNode *res;
- struct sNode *top;
- if(isEmpty(*top_ref))
- {
- printf("Stack Underflow \n");
- getchar();
- exit(0);
- }
- else
- {
- top = *top_ref;
- res = top->t;
- *top_ref = top->next;
- free(top);
- return res;
- }
- }
- struct tNode* newtNode(char data)
- {
- struct tNode* tNode = (struct tNode*)
- malloc(sizeof(struct tNode));
- tNode->data = data;
- tNode->left = NULL;
- tNode->right = NULL;
- return(tNode);
- }
- int Ve_HT(int x, int y, int r,int color)
- {
- setcolor(color);
- circle(x,y,r);
- }
- int Ve_DT(int x1, int y1, int x2, int y2, int color)
- {
- setcolor(color);
- line(x1,y1,x2,y2);
- }
- int In_Text(int x, int y, char *s, int color)
- {
- setcolor(color);
- outtextxy(x,y,s);
- }
- void To_mau(int x, int y, int r,int m, int n, int color,char *k)
- {
- setcolor(color);
- circle(x,y,r);
- settextstyle(0,HORIZ_DIR,3);
- In_Text(x,y+5,k,color);
- Beep(i,500);
- i+=50;
- setcolor(color);
- Ve_HT(m,n,30, color);
- settextstyle(0,HORIZ_DIR,3);
- settextjustify(1,1);
- In_Text(m,n+5,k,color);
- delay(1500);
- }
- void inOrder(struct tNode *root)
- {
- /* set current to root of binary tree */
- struct tNode *current = root;
- struct sNode *s = NULL; /* Initialize stack s */
- bool done = 0;
- int count = 0;
- char s1[1];
- char* ret = NULL;
- char c[11];
- while (!done)
- {
- if(current != NULL)
- {
- push(&s, current);
- current = current->left;
- }
- else
- {
- if (!isEmpty(s))
- {
- current = pop(&s);
- strncpy(s1,¤t->data ,1);
- ret = new char[1];
- ret[0] = s1[0];
- count++;
- switch (count)
- {
- case 1:
- To_mau(500,600,25,400,280,RED,ret);
- break;
- case 2:
- To_mau(580,600,25,500,450,BLUE,ret);
- break;
- case 3:
- To_mau(660,600,25,500,120,YELLOW,ret);
- break;
- case 4:
- To_mau(740,600,25,600,280,GREEN,ret);
- break;
- case 5:
- To_mau(820,600,25,683,50,CYAN,ret);
- break;
- case 6:
- To_mau(900,600,25,766,280,LIGHTRED,ret);
- break;
- case 7:
- To_mau(980,600,25,866,120,LIGHTBLUE,ret);
- break;
- case 8:
- To_mau(1060,600,25,966,280,LIGHTMAGENTA,ret);
- break;
- case 9:
- To_mau(1140,600,25,1066,450,DARKGRAY,ret);
- break;
- }
- current = current->right;
- }
- else
- done = 1;
- }
- }
- }
- int main()
- {
- struct tNode *root = NULL;
- root = newtNode('A');
- root->left = newtNode('C');
- root->right = newtNode('B');
- root->left->left = newtNode('G');
- root->left->right = newtNode('F');
- root->left->left->right = newtNode('I');
- root->right->left = newtNode('E');
- root->right->right = newtNode('D');
- root->right->right->right = newtNode('H');;
- initwindow(1366,768);
- Ve_HT(683,50,30, WHITE); //Muc 1
- delay(500);
- settextstyle(0,HORIZ_DIR,3);
- settextjustify(1,1);
- In_Text(683,55,"A",WHITE);
- Ve_DT(652,50,526,105, WHITE);
- Ve_DT(712,50,840,105, WHITE);
- Ve_HT(500,120,30, WHITE);//Muc 2
- delay(500);
- settextstyle(0,HORIZ_DIR,3);
- settextjustify(1,1);
- In_Text(500,125,"C",WHITE);
- Ve_HT(866,120,30, WHITE);
- delay(500);
- settextstyle(0,HORIZ_DIR,3);
- settextjustify(1,1);
- In_Text(866,125,"B",WHITE);
- Ve_DT(475,135,415,255, WHITE);
- Ve_DT(525,135,585,255, WHITE);
- Ve_DT(840,135,776,255, WHITE);
- Ve_DT(892,135,950,255, WHITE);
- Ve_HT(400,280,30, WHITE);//Muc 3
- delay(500);
- settextstyle(0,HORIZ_DIR,3);
- settextjustify(1,1);
- In_Text(400,285,"G",WHITE);
- Ve_HT(600,280,30, WHITE);
- delay(500);
- settextstyle(0,HORIZ_DIR,3);
- settextjustify(1,1);
- In_Text(600,285,"F",WHITE);
- Ve_HT(766,280,30, WHITE);
- delay(500);
- settextstyle(0,HORIZ_DIR,3);
- settextjustify(1,1);
- In_Text(766,285,"E",WHITE);
- Ve_HT(966,280,30, WHITE);
- delay(500);
- settextstyle(0,HORIZ_DIR,3);
- settextjustify(1,1);
- In_Text(966,285,"D",WHITE);
- Ve_DT(375,295,515,425, WHITE);
- Ve_DT(990,295,1055,425, WHITE);
- Ve_HT(500,450,30, WHITE);//Muc 4
- delay(500);
- settextstyle(0,HORIZ_DIR,3);
- settextjustify(1,1);
- settextstyle(0,HORIZ_DIR,3);
- In_Text(500,455,"I",WHITE);
- Ve_HT(1066,450,30, WHITE);
- settextjustify(1,1);
- In_Text(1066,455,"H",WHITE);
- settextstyle(0,HORIZ_DIR,2);
- In_Text(300,600,"Thu tu duyet giua la: ", WHITE);
- system("pause");
- inOrder(root);
- getch();
- return 0;
- closegraph();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement