I've given a n-ary tree in .txt file, where first integer is parent and the next ones are child of it:
1 2 3 4 5 6
1 2 3 4 5
3 6 7
5 8
8 9 10 11
0 (represents the end of the tree)
And, it could also be written like this (same tree):
1 2 3 4 5
5 8
3 6 7
8 9 10 11
1 2 3 4 5
0
My task is to output result as (First example):
1 2 3 4 5
1 5 4 3 2
5 8
8 11 10 9
3 7 6
0
I'm really desperate to find a solution here and I my brains are slowly giving up. I've a function to read from .txt file and put all the values in the array. (I know that I shouldn't use EOF, but atm, that's not the problem we should focus on..)
How can I correctly make a tree and get the correct output?
1 is root (have to check it tho - not sure how, cuz tree can be given with second example).
rest of the numbers are child of 1.
Repeat with each line and you get (left picture): https://img.exs.lv/e/z/ezeliitis/image001.jpg
Task: Computer understands tree, if it's structure is: every line contains information about inside node (not a leaf); On every line - first integer is node and the next ones are childrens. Tree can be structured differently, for instance: .txt file
1 2 3 4
1 2 3 4 5
3 6 7
5 8
8 9 10 11
AS WELL AS:
1 2 3 4
5 8
3 6 7
8 9 10 11
1 2 3 4 5
It's mandatory to output tree's inside nodes in pre-order, first comes parent, then child information. Nodes in the tree can be up to 100. What I need to do? - output the tree in mirror style.