本文整理汇总了C#中Tree.AddNode方法的典型用法代码示例。如果您正苦于以下问题:C# Tree.AddNode方法的具体用法?C# Tree.AddNode怎么用?C# Tree.AddNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tree
的用法示例。
在下文中一共展示了Tree.AddNode方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
Tree<int> tree = new Tree<int>();
TreeNode<int> one = new TreeNode<int>(3);
TreeNode<int> two = new TreeNode<int>(5, one);
TreeNode<int> three = new TreeNode<int>(2, one);
TreeNode<int> four = new TreeNode<int>(0, two);
TreeNode<int> five = new TreeNode<int>(1, two);
TreeNode<int> six = new TreeNode<int>(6, two);
TreeNode<int> seven = new TreeNode<int>(4, three);
tree.AddNode(one);
tree.AddNode(two);
tree.AddNode(three);
tree.AddNode(four);
tree.AddNode(five);
tree.AddNode(six);
tree.AddNode(seven);
var treeRoot = tree.DetermineRoot(); // a)
Console.WriteLine(treeRoot);
var treeLeafes = tree.GetLeafes(); // b)
Console.WriteLine(string.Join(",", treeLeafes));
var treeMiddles = tree.GetMiddleNodes(); // c)
Console.WriteLine(string.Join(",", treeMiddles));
Console.WriteLine(DetermineLongestPath(one)); // d)
FindPathsWithSumS(9, one); // e)*
}
示例2: InitializeProgram
private void InitializeProgram()
{
Book root = new Book();
root.NodeID = Guid.NewGuid().ToString();
root.NodeName = "Root";
_programManageBooks = new Tree<Book>();
_programManageBooks.AddNode("", root);
BindingTree(_programManageBooks);
}
示例3: TreePreorderBypass_NewCompareInt_Test
public static string TreePreorderBypass_NewCompareInt_Test(int[] array)
{
string s = "";
Tree<int> tree = new Tree<int>(new CompareInt());
foreach (int a in array)
tree.AddNode(a);
foreach (int a in tree.PreorderIterator())
s += a;
Debug.WriteLine(s);
return s;
}
示例4: TreeInorderIteratorTest
public static string TreeInorderIteratorTest(int[] array)
{
string s = "";
Tree<int> tree = new Tree<int>();
foreach(var a in array)
tree.AddNode(a);
foreach (int a in tree.InorderIterator())
s += a;
Debug.WriteLine(s);
return s;
}
示例5: TreePostorderIteratorTest
public static string TreePostorderIteratorTest(int[] array)
{
string s = "";
Tree<int> tree = new Tree<int>(array[0]);
for (int a = 1; a < array.Length; a++)
tree.AddNode(array[a]);
foreach (int a in tree.PostorderIterator())
s += a;
Debug.WriteLine(s);
return s;
}
示例6: ReadInput
private static Tree<int> ReadInput()
{
var tree = new Tree<int>();
var numberOfNodes = int.Parse(Console.ReadLine());
for (int i = 0; i < numberOfNodes - 1; i++)
{
var line = Console.ReadLine();
var splittedLine = line.Split().Select(int.Parse).ToArray();
var nodeValue = splittedLine[0];
tree.AddNode(nodeValue);
var childValue = splittedLine[1];
tree.AddChildren(childValue, nodeValue);
}
return tree;
}
示例7: MakeTreeFromGraph
public void MakeTreeFromGraph(Coord rootNode)
{
//List<Coord> connectedNodes = new List<Coord>(this.nodes);
// List<Coord> unconnectedNodes = new List<Coord>(this.nodes);
//connectedNodes.Add(rootNode);
Queue<Coord> nodesToConnect = new Queue<Coord>();
nodesToConnect.Enqueue(rootNode);
List<Coord>[,] tempLinkArray = new List<Coord>[this.linkArray.GetLength(0),this.linkArray.GetLength(1)];
Array.Copy(this.linkArray,tempLinkArray,this.linkArray.GetLength(0)*this.linkArray.GetLength(1));
Tree newTree = new Tree(rootNode);
//Coord lastParent = rootNode;
while (nodesToConnect.Count > 0) {
Coord node = nodesToConnect.Dequeue();
List<Coord> linkedNodes = GetLinksFromNode(node,tempLinkArray);
tempLinkArray = DisconnectNode(node,tempLinkArray);
// List<Coord> unconnectedLinkedNodes = new List<Coord>();
// foreach(Coord linkedNode in linkedNodes) {
// if (unconnectedNodes.Contains(linkedNode)) {
// unconnectedLinkedNodes.Add (linkedNode);
// }
// }
foreach (Coord linkedNode in linkedNodes) {
if (nodesToConnect.Contains(linkedNode) == false) {
newTree.AddNode(node,linkedNode);
nodesToConnect.Enqueue(linkedNode);
}
// foreach (Coord unconnectedNode in unconnectedNodes) {
// if (CoordsAreEqual(unconnectedNode,linkedNode)) {
// unconnectedNodes.Remove(unconnectedNode);
// break;
// }
// }
}
}
this.tree = newTree;
Debug.Log ("Graph Nodes: " + nodes.Count.ToString());
Debug.Log ("Tree Nodes: " + tree.nodes.Count.ToString());
}
示例8: TreePreorderBypass_NewCompareString_Test
public void TreePreorderBypass_NewCompareString_Test()
{
string s = "";
string[] array = new string[] { "500", "40", "5", "37", "1000", "10000" };
Tree<string> tree = new Tree<string>(new CompareString());
foreach (var a in array)
tree.AddNode(a);
foreach (var a in tree.PreorderIterator())
s += a;
Assert.AreEqual(s, "50040537100010000");
}
示例9: TreeInorderBypassBook_NewComparer_Test
public void TreeInorderBypassBook_NewComparer_Test()
{
string s = "";
Tree<Book> tree = new Tree<Book>(new CompareBook());
tree.AddNode(new Book() { Author = "Лев Толстой", Title = "Война и мир", Genre = "Роман", Year = 1869 });
tree.AddNode(new Book() { Author = "Алан Александр Милн", Title = "Вини-Пух", Genre = "Детский рассказ", Year = 1926 });
tree.AddNode(new Book() { Author = "Мари Шелли", Title = "Франкенштейн", Genre = "Научная фантастика", Year = 1818 });
tree.AddNode(new Book() { Author = "Михаил Булгаков", Title = "Мастер и Маргарита", Genre = "Роман", Year = 1966 });
tree.AddNode(new Book() { Author = "Федор Достоевский", Title = "Преступление и наказание", Genre = "Роман", Year = 1866 });
foreach (var a in tree.InorderIterator())
s += a.Title;
Assert.AreEqual(s, "Вини-ПухВойна и мирФранкенштейнМастер и МаргаритаПреступление и наказание");
}
示例10: Sync
public void Sync(Tree<RemoteFileInfo> _tree, Tree<RemoteFileInfo> _tempIgnoreTree, string _remotePath, string _localPath, bool _remove = false, TransferOptions _transformOptions = null)
{
try
{
if (_tree.Children.Count != 0)
{
for (int i = 0; i < _tree.Children.Count; i++)
{
if (_tree.Children[i] != null)
{
if (_tree.Children[i].Children != null)
{
string data = _tree.Children[i].Data.ToString();
if (data == null)
{
data = string.Empty;
}
Tree<RemoteFileInfo> node = _tree.Children[i];
_tempIgnoreTree.AddNode(node);
Console.WriteLine("AT -> {0}", node.Data);
Sync(_tree.Children[i], _tempIgnoreTree.Children[_tempIgnoreTree.Children.Count - 1], _remotePath + "/" + data, _localPath, _remove, _transformOptions);
}
}
}
}
else
{
if (_tree.Data != null)
{
string data = _tree.Data.ToString();
if (data != null)
{
string source = _remotePath + "/" + data;
if (!TestMode)
{
GetFiles(source, _localPath, _remove, _transformOptions);
}
else
{
//Console.WriteLine("Syncing {0} to {1}", source, _localPath);
}
Console.WriteLine("-------------DUMP--------------");
Tree<RemoteFileInfo>.PrintTree(_tempIgnoreTree, 0);
Console.WriteLine("--------------END--------------");
m_ignoreTree.AddNode(Tree<RemoteFileInfo>.Clone(_tempIgnoreTree));
_tempIgnoreTree = null;
_tempIgnoreTree = new Tree<RemoteFileInfo>();
m_syncedFiles++;
}
}
}
}
catch (Exception e)
{
LOG.ErrorFormat("Error: {0}", e);
}
}
示例11: CreateMenuData
private Tree<ACMenu> CreateMenuData()
{
Tree<ACMenu> tree = new Tree<ACMenu>();
ACMenu m1 = new ACMenu() { NodeID = Guid.NewGuid().ToString(), MenuCaption = "菜单" };
ACMenu m2m = new ACMenu() { NodeID = Guid.NewGuid().ToString(), MenuCaption = "tests" };
ACMenu m2 = new ACMenu()
{ NodeID = Guid.NewGuid().ToString(), MenuCaption = "testtree", UriCode = "testtree" };
ACMenu m3 = new ACMenu() { NodeID = Guid.NewGuid().ToString(), MenuCaption = "datamaintain" };
ACMenu m4 = new ACMenu()
{ NodeID = Guid.NewGuid().ToString(), MenuCaption = "customerMaintain", UriCode="testcustomer" };
ACMenu m5 = new ACMenu()
{ NodeID = Guid.NewGuid().ToString(), MenuCaption = "urimanage", UriCode="urimanagement" };
//ACMenu m6 = new ACMenu() { NodeID = Guid.NewGuid().ToString(), MenuCaption = "dbmaintain" };
//ACMenu m7 = new ACMenu() { NodeID = Guid.NewGuid().ToString(), MenuCaption = "dbmanagment" };
//ACMenu m10 = new ACMenu()
//{ NodeID = Guid.NewGuid().ToString(), MenuCaption = "createdb", UriCode="installdb" };
//ACMenu m8 = new ACMenu()
//{ NodeID = Guid.NewGuid().ToString(), MenuCaption = "initdata", UriCode = "initialdata" };
//ACMenu m9 = new ACMenu()
//{ NodeID = Guid.NewGuid().ToString(), MenuCaption = "deldb", UriCode = "deletedb" };
ACMenu m11 = new ACMenu()
{ NodeID = Guid.NewGuid().ToString(), MenuCaption = "supporttest", UriCode = "supporttest" };
ACMenu m13 = new ACMenu()
{
NodeID = Guid.NewGuid().ToString(),
MenuCaption = "simpletabletest",
UriCode = "simpletabletest"
};
ACMenu m12 = new ACMenu()
{
NodeID = Guid.NewGuid().ToString(),
MenuCaption = "testpageinfo",
UriCode = "testpageinfo"
};
ACMenu m14 = new ACMenu()
{
NodeID = Guid.NewGuid().ToString(),
MenuCaption = "testpaginationtable",
UriCode = "testpaginationtable"
};
ACMenu m15 = new ACMenu()
{
NodeID = Guid.NewGuid().ToString(),
MenuCaption = "testrefreshtable",
UriCode = "testrefreshtable"
};
ACMenu m16 = new ACMenu()
{
NodeID = Guid.NewGuid().ToString(),
MenuCaption = "testeditabletable",
UriCode = "testeditabletable"
};
ACMenu m17 = new ACMenu()
{
NodeID = Guid.NewGuid().ToString(),
MenuCaption = "testsearchtable",
UriCode = "testsearchtable"
};
tree.AddNode("", m1);
tree.AddNode(m1, m2m);
tree.AddNode(m2m, m2);
tree.AddNode(m2m, m4);
tree.AddNode(m2m, m11);
tree.AddNode(m2m, m13);
tree.AddNode(m2m, m14);
tree.AddNode(m2m, m15);
tree.AddNode(m2m, m16);
tree.AddNode(m2m, m17);
tree.AddNode(m1, m3);
tree.AddNode(m3, m5);
//tree.AddNode(m1, m6);
//tree.AddNode(m6, m7);
//tree.AddNode(m7, m9);
//tree.AddNode(m7, m10);
//tree.AddNode(m6, m8);
tree.AddNode(m2m, m12);
return tree;
}