Skip to content

Instantly share code, notes, and snippets.

@catharsis96
Created October 12, 2016 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catharsis96/aad1e4ba09355b6911fcfe22a1a6c9c9 to your computer and use it in GitHub Desktop.
Save catharsis96/aad1e4ba09355b6911fcfe22a1a6c9c9 to your computer and use it in GitHub Desktop.
#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