Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct
- {
- int value; // value of node
- struct Node* parent; // parent of node (if its root node, this pointer must be null
- struct Node* child1;
- struct Node* child2;
- } Node;
- Node* createNode(Node* &parent) {
- Node* node = (Node*)malloc(sizeof(Node));
- node->parent = parent;
- printf("Parent is %p\n", &parent);
- return node;
- }
- void createTree(Node* &parent, size_t depth) {
- if (depth != 0) {
- parent->child1 = createNode(parent);
- parent->child2 = createNode(parent);
- //printf("Creating tree\n");
- //printf("Depth is %d\n", depth);
- //printf("Parent adress = %p\n", &parent);
- //printf("Child1 adress = %p\n", &parent->child1);
- //printf("Child2 adress = %p\n\n", &parent->child2);
- createTree(parent->child1, depth - 1);
- createTree(parent->child2, depth - 1);
- }
- return;
- }
- int main()
- {
- size_t depth = 5;
- Node* main = createNode(0);
- createTree(main, 5);
- //printf("Insert depth\n");
- //scanf("%d", &depth);
- return 0;
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement