我还是编程新手。
我在树中手动添加节点。如何生成具有 500 或 1000 个不平衡节点的树?也许有 15 个级别,并且每次运行程序时都可能生成。它将生成一棵不同的树。也许在高度或宽度上更多。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model.Trees;
/* Adding nodes manully to the tree*/
namespace UserInterface.Samples
{
public abstract class SampleTree1
{
public static Tree TreeSample()
{
var tree = new Tree();
var root = new Node("Burgle House");
Node node1 = new Node(" Defeat Door security");
Node node2 = new Node(" Open front OR back doors ");
Node node3 = new Node(" Open Door using gift card or credit card");
Node node4 = new Node(" using trees");
Node node5 = new Node(" Enter via Windows ");
Node node6 = new Node(" Cover the window in duct tape and gently shatter the enti");
Node node7 = new Node(" Garage Attack ");
Node node8 = new Node(" Enter Garage ");
Node node9 = new Node(" Open car door ");
Node node10 = new Node(" Brutal Force on the Garage Door)");
Node node11 = new Node(" Put Door opener code");
Node node12 = new Node(" EavesDrop opener code)");
Node node13 = new Node(" Steal opener from Car)");
Node node14 = new Node(" Cut the hole in the wall or roof ");
Node node15 = new Node(" Penitrate House ");
Node node16 = new Node(" Open passger door ");
Node node17 = new Node("break Down the passanger door");
Node node18 = new Node(" Pick lock");
Node node19 = new Node(" Steal Keys");
Node node20 = new Node(" Cut the hole in the wall or roof ");
Node node21 = new Node(" Cut the wall or roof ");
Node node22 = new Node(" Chimney attack ");
Node node23 = new Node(" Tunnel through the floor ");
Node node24 = new Node(" Social engineering ");
Node node25 = new Node(" A bomb blast");
Node node26 = new Node(" Call a locksmith");
/*Add nodes to the tree*/
tree.AddNode(root, null);
tree.AddNode(node1, root);
tree.AddNode(node2, node1);
tree.AddNode(node3, node1);
tree.AddNode(node4, root);
tree.AddNode(node5, root);
tree.AddNode(node6, node5);
tree.AddNode(node7, root);
tree.AddNode(node8, node7);
tree.AddNode(node9, node8);
tree.AddNode(node10, node9);
tree.AddNode(node11, node9);
tree.AddNode(node12, node11);
tree.AddNode(node13, node11);
tree.AddNode(node14, node8);
tree.AddNode(node15, node7);
tree.AddNode(node16, node15);
tree.AddNode(node17, node16);
tree.AddNode(node18, node16);
tree.AddNode(node19, node16);
tree.AddNode(node20, node15);
tree.AddNode(node21, root);
tree.AddNode(node22, root);
tree.AddNode(node23, root);
tree.AddNode(node24, root);
tree.AddNode(node25, root);
tree.AddNode(node26, root);
return tree;
}
}
}