Варіант 1 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <conio.h> struct node { int data; struct node *left; struct node *right; }; node* newNode(int data) { node* node = (node*)malloc(sizeof(node)); node->data = data; node->left = NULL; node->right = NULL; return node; } int main() { struct node *root = newNode(1); printf("%d", root->data); /* 1 / \ NULL NULL */ root->left = newNode(2); root->right = newNode(3); /* 1 / \ 2 3 / \ / \ NULL NULL NULL NULL */ root->left->left = newNode(4); /* 1 / \ 2 3 / \ / \ 4 NULL NULL NULL / \ NULL NULL */ _getch(); return 0; }
Варіант 2 Код
Варіант 3 github.com