Created
October 12, 2016 12:48
-
-
Save catharsis96/aad1e4ba09355b6911fcfe22a1a6c9c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <iostream> | |
struct tree { | |
int k, n; | |
tree **son; | |
}; | |
tree *root = NULL; | |
tree *node; | |
void add(tree *); | |
void main() | |
{ | |
node = new tree; | |
root = node; | |
printf("Enter the key of the root\n"); | |
scanf_s("%d", &node->k); | |
add(node); | |
//getch(); | |
} | |
void add(tree *c) | |
{ | |
int i; | |
printf("Enter the number of sons\n"); | |
scanf_s("%d", &c->n); | |
if (c->n == 0) | |
{ | |
c->son = NULL; | |
return; | |
} | |
c->son = new tree*[c->n]; | |
for (i = 0;i<c->n;i++) | |
{ | |
c->son[i] = new tree; | |
printf("Enter the key of the node %d\n", i); | |
scanf_s("%d", &c->son[i]->k); | |
printf("\n%d", c->son[i]->k); | |
} | |
for (i = 0;i<c->n;i++) | |
add(c->son[i]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment