#include<iostream>
#include<cstdlib>
#include<vector>
class Node
{
public:
int val;
vector<Node*> children;
Node(int _val, vector<Node*> _children)
{
val = _val;
children = _children;
}
};
class Solution
{
public:
vector<int> v;
vector<int> preorder(Node* root)
{
if(root == NULL ) return {};
for(int i=0; i < root->children.size(); i++)
{
preorder(root->children[i]);
}
Node *insert_node(Node *root,int data)
{
Node *current;
Node *newnode;
newnode=new (Node);
newnode->val=data;
if(root==NULL)
{
root=newnode;
return root;
}
else
{
if(root->children.size()<3)
root->children.push_back(newnode);
else
{
current=root->children[0];
current->children.push_back(newnode);
}
Node *create_tree(int *data,int len)
{
Node *root=NULL;
int i;
for(i=0;i<len;i++)
{
root=insert_node(root,data[i]);
}
int main()
{
int i;
int data[6]={1,3,2,4,5,6};
Node *Ntree;
Solution operate;
Ntree=operate.create_tree(data,6);
arr=operate.preorder(Ntree);
for(i=0;i<arr.size();i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
system("PAUSE");
return 0;
}