Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define MIN_SIZE 0
- #define MAX_SIZE 20
- #define MAX_DEPTH 5
- #define OFFSET 30
- #define LEFT 0
- #define RIGHT 1
- int foo(short n) {
- switch (n) {
- case 1:
- return 8;
- break;
- case 2:
- return 4;
- break;
- case 3:
- return 2;
- break;
- case 4:
- return 1;
- break;
- default: return -1;
- }
- }
- void printTree(Node* tree, int currentSet, short depth, int index, char** str) {
- if (!tree || depth < 1 || depth > MAX_DEPTH)
- return;
- int x = currentSet;
- int z = foo(depth);
- char* s = str[index];
- s += currentSet - 1;
- int a = sprintf(s, "%2d", tree->field);
- s[2] = ' ';
- currentSet--;
- index++;
- for (int j = 0; j < z; j++) {
- s = str[index];
- s += currentSet;
- if (tree->left)
- s[0] = '/';
- s += (x - currentSet) * 2;
- if (tree->right)
- s[0] = '\\';
- index++;
- currentSet--;
- }
- printTree(tree->left, currentSet, depth + 1, index, str);
- printTree(tree->right, (x + z + 1), depth + 1, index, str);
- }
- char** str = new char* [64];
- for (int i = 0; i < 64; i++) {
- str[i] = new char[64];
- memset(str[i], ' ', 64);
- str[i][63] = 0;
- }
- printTree(tree, OFFSET, 1, 0, str);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement