本文整理汇总了C#中BinaryTree.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryTree.Remove方法的具体用法?C# BinaryTree.Remove怎么用?C# BinaryTree.Remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryTree
的用法示例。
在下文中一共展示了BinaryTree.Remove方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
BinaryTree<int> tree = new BinaryTree<int>();
tree.Insert(2);
tree.Insert(3);
tree.Insert(5);
tree.Insert(8);
tree.Insert(11);
tree.Insert(200);
tree.Insert(120);
tree.Insert(600);
Console.WriteLine(tree);
Console.WriteLine(tree.Count);
tree.Remove(2);
tree.Remove(5);
tree.Remove(8);
Console.WriteLine(tree);
tree.Remove(11);
tree.Remove(200);
tree.Remove(120);
tree.Remove(600);
tree.Remove(3);
Console.WriteLine(tree);
Console.WriteLine(tree.Count);
tree.Insert(10);
tree.Insert(20);
tree.Insert(30);
tree.Insert(60);
tree.Insert(1);
tree.Insert(500);
tree.Insert(2);
Console.WriteLine(tree);
Console.WriteLine(tree.Count);
var newTree = new BinaryTree<int>();
newTree.Insert(10);
newTree.Insert(20);
newTree.Insert(30);
newTree.Insert(60);
newTree.Insert(1);
newTree.Insert(500);
newTree.Insert(2);
Console.WriteLine(newTree);
Console.WriteLine(newTree.Count);
Console.WriteLine(tree.Equals(newTree));
foreach (var value in tree)
{
Console.WriteLine(value);
}
BinaryTree<int> r = null;
Console.WriteLine(tree.Equals(r));
int a = 5;
Console.WriteLine(a.Equals(null));
}
示例2: TestMethod_remove
public void TestMethod_remove()
{
BinaryTree<int> bt = new BinaryTree<int>();
bt.Add(10);
Assert.AreEqual(true, bt.Remove(10));
}
示例3: Interface
public void Interface()
{
ITree<int> binaryTree = new BinaryTree<int>(5);
var child1 = new BinaryTree<int>(4);
var child2 = new BinaryTree<int>(6);
var child3 = new BinaryTree<int>(7);
binaryTree.Add(child1);
binaryTree.Add(child2);
Assert.AreEqual(binaryTree.Degree, 2);
Assert.IsTrue(binaryTree.Remove(child1));
Assert.AreEqual(binaryTree.Degree, 1);
Assert.IsFalse(binaryTree.Remove(child3));
Assert.AreEqual(binaryTree.Degree, 1);
Assert.IsTrue(binaryTree.Remove(child2));
Assert.AreEqual(binaryTree.Degree, 0);
}
示例4: Main
static void Main(string[] args)
{
BinaryTree<int> tree = new BinaryTree<int>();
tree.Add(1);
tree.Add(4);
tree.Add(2);
tree.Add(55);
tree.Add(3);
tree.Remove(55);
tree.Add(56);
tree.Print();
Console.Read();
}
示例5: FurtherRandomTest
public void FurtherRandomTest()
{
var seq = Enumerable.Range(0, 100).Shuffle(new Random()).ToArray();
var seqRemove = Enumerable.Range(0, 100).Where(i => i%3 == 0).Shuffle(new Random()).ToArray();
var d = new BinaryTree<int, int>();
foreach (var i in seq)
d.Add(i, i*100);
foreach (var i in seqRemove)
d.Remove(i);
Assert.AreEqual(string.Join(",", seq.Except(seqRemove).OrderBy(i => i).ToArray()),
string.Join(",", d.Keys.ToArray()));
}
示例6: Main
public static void Main()
{
var binaryTree = new BinaryTree<int>();
Console.WriteLine("The binary tree created.");
AddNumber(binaryTree, 5);
AddNumber(binaryTree, 20);
AddNumber(binaryTree, 14);
AddNumber(binaryTree, 11);
AddNumber(binaryTree, 8);
AddNumber(binaryTree, 3);
AddNumber(binaryTree, 1);
AddNumber(binaryTree, 5);
binaryTree.Remove(5);
Console.WriteLine("Deleted 5");
Traverse(binaryTree.Root, "");
Console.WriteLine("----------------------");
}
示例7: Main
static void Main(string[] args)
{
DateTime testdata = new DateTime(2014, 10, 20);
TestInfo a = new TestInfo("dima", "firsttest", testdata, 9);
testdata = new DateTime(2014, 11, 20);
TestInfo b = new TestInfo("oleg", "firsttest", testdata, 4);
BinaryTree<TestInfo> tree = new BinaryTree<TestInfo>();
tree.Add(a);
tree.Add(b);
foreach (TestInfo c in tree)
{
Console.WriteLine(c.ToString());
}
tree.Remove(a);
foreach (TestInfo c in tree)
{
Console.WriteLine(c.ToString());
}
if (!tree.IsReadOnly)
{
Console.WriteLine("not only for reading");
}
testdata = new DateTime(2014, 11, 10);
TestInfo d = new TestInfo("pasha", "secondtest", testdata, 8);
tree.Add(a);
tree.Add(d);
foreach (TestInfo c in tree)
{
Console.WriteLine(c.ToString());
}
if (tree.Contains(a))
{
Console.WriteLine("Tree contains this element");
}
Console.ReadLine();
}
示例8: Remove_NodeWithOneChildFromIntTree_SavesRightStructure
public void Remove_NodeWithOneChildFromIntTree_SavesRightStructure()
{
BinaryTree<int> tree = new BinaryTree<int>(new int[] { 54, 25, 316, 4, 55, 6, });
tree.Remove(4);
int[] actual = new int[5];
int i = 0;
foreach (var item in tree.InOrderTraversal)
actual[i++] = item;
IStructuralEquatable expected = new int[] {6, 25, 54, 55, 316 };
Assert.IsTrue(expected.Equals(actual, StructuralComparisons.StructuralEqualityComparer));
}
示例9: Remove_LeafFromIntTree_RemovesIt
public void Remove_LeafFromIntTree_RemovesIt()
{
BinaryTree<int> tree = new BinaryTree<int>(new int[] { 54, 25, 316, 4, 55, 6, });
tree.Remove(55);
Assert.AreEqual(5, tree.Count);
}
示例10: RemoveSingleTest
private static void RemoveSingleTest(int[] sequence, int remove)
{
var d = new BinaryTree<int, int>();
foreach (var i in sequence)
d.Add(i, i*100);
Assert.IsTrue(d.Remove(remove), "Remove " + remove);
Assert.AreEqual(string.Join(",", sequence.Where(i => i != remove).OrderBy(i => i).ToArray()),
string.Join(",", d.Keys.ToArray()),
"Remove " + remove);
}
示例11: RemoveTest
public void RemoveTest()
{
var tree = new BinaryTree<int>();
var node0 = new BinaryTreeNode<int>(0);
var node1 = new BinaryTreeNode<int>(1);
var node2 = new BinaryTreeNode<int>(2);
var node3 = new BinaryTreeNode<int>(3);
var node4 = new BinaryTreeNode<int>(4);
var node5 = new BinaryTreeNode<int>(5);
var node6 = new BinaryTreeNode<int>(6);
var node7 = new BinaryTreeNode<int>(7);
var node8 = new BinaryTreeNode<int>(8);
var node9 = new BinaryTreeNode<int>(9);
var node10 = new BinaryTreeNode<int>(10);
var node11 = new BinaryTreeNode<int>(11);
var node12 = new BinaryTreeNode<int>(12);
var node13 = new BinaryTreeNode<int>(13);
var node14 = new BinaryTreeNode<int>(14);
var node15 = new BinaryTreeNode<int>(15);
var node16 = new BinaryTreeNode<int>(16);
tree.Add(node8);
tree.Add(node4);
tree.Add(node12);
tree.Add(node2);
tree.Add(node6);
tree.Add(node10);
tree.Add(node14);
tree.Add(node1);
tree.Add(node3);
tree.Add(node5);
tree.Add(node7);
tree.Add(node9);
tree.Add(node11);
tree.Add(node13);
tree.Add(node15);
tree.Add(node0);
tree.Add(node16);
// Structure:
// 8
// 4 12
// 2 6 10 14
// 1 3 5 7 9 11 13 15
//0 16
tree.Remove(4);
Assert.AreEqual(node6, tree.Top.Left);
Assert.AreEqual(node2, tree.Top.Left.Left.Left);
tree.Remove(15);
Assert.AreEqual(node16, tree.Top.Right.Right.Right);
tree.Remove(1);
Assert.AreEqual(node0, tree.Top.Left.Left.Left.Left);
tree.Remove(8);
Assert.AreEqual(node12, tree.Top);
Assert.AreEqual(node6, tree.Top.Left.Left.Left);
}
示例12: Main
//.........这里部分代码省略.........
Console.WriteLine("Position 5: " + list.Retrieve(5).NodeContent);
Console.WriteLine();
Console.WriteLine("Deleting node 5");
list.Delete(5);
Console.WriteLine();
Console.WriteLine("Position 5: " + list.Retrieve(5).NodeContent);
Console.WriteLine();
list.ListNodes();
Console.ReadLine();
//double linked list
DoubleLinkedList listdl = new DoubleLinkedList();
listdl.Insert("1");
listdl.Insert("2");
listdl.Insert("3");
DoubleLink link4 = listdl.Insert("4");
listdl.Insert("5");
Console.WriteLine("List: " + listdl);
listdl.InsertAfter(link4, "[4a]");
Console.WriteLine("List: " + listdl);
Console.Read();
link4 = listdl.Find ("[4a]");
listdl.Delete (link4);
Console.WriteLine ("List after delete:" + listdl);
listdl.Delete ();
Console.WriteLine ("list after delete first:" + listdl);
Console.Read ();
string str = "hello reverse words hello";
Console.WriteLine(str);
StringExamples mystring = new StringExamples();
Console.WriteLine(mystring.reverseWords(str));
Console.WriteLine("Reverse Recursively");
Console.WriteLine(mystring.reverseRecursively(str));
string str2 = "Reverse words in-place";
Console.WriteLine(str2);
Console.WriteLine(mystring.reverseWordsInPlace(str2));
string str3 = "remove whitespace\t\t\tin place";
Console.WriteLine(str3);
Console.WriteLine(mystring.removeWhitespaceInplace(str3));
string str4 = "AAA BBB CC D EE A";
Console.WriteLine("remove duplicate characters" + str4);
Console.Write(mystring.removeDuplicateChars(str4));
char c=mystring.firstNonRepeatedCharacter(str);
Console.WriteLine("\nThe first non repeated character in '" + str + "' is : " + c);
BinaryTree<int> btree = new BinaryTree<int>();
//btree.Root = new BinaryTreeNode<int>(1);
//btree.Root.Left = new BinaryTreeNode<int>(2);
//btree.Root.Right = new BinaryTreeNode<int>(3);
//btree.Root.Left.Left = new BinaryTreeNode<int>(4);
//btree.Root.Right.Right = new BinaryTreeNode<int>(5);
//btree.Root.Left.Left.Right = new BinaryTreeNode<int>(6);
//btree.Root.Right.Right.Right = new BinaryTreeNode<int>(7);
//btree.Root.Right.Right.Right.Right = new BinaryTreeNode<int>(8);
Random rnd = new Random();
int j;
for (int i = 0; i < 8; i++) {
j = rnd.Next (1, 20);
Console.Write (j + ",");
btree.Add (j);
}
Console.WriteLine ("");
// manual sorting?
btree.PreorderTraversal (btree.Root);
btree.Add (4);
Console.WriteLine ("\n Added 4");
btree.InorderTraversal (btree.Root);
Console.WriteLine ("\n Remove 4");
btree.Remove (4);
btree.InorderTraversal (btree.Root);
Arrays arr = new Arrays();
//Console.WriteLine("\nfind dup int:" + arr.FindDuplicateInt ());
Console.WriteLine ("\nfind missing int: " + arr.FindMissingInt ());
int [] arr2 = {-1,6,-2,-3,5,-7,5,-10,0,1,9,1,-2};
int start;
int end;
Console.WriteLine ("\nfind best subsequence total: " + arr.FindBestSubsequence(arr2,out start, out end) + "start:"+ start + "end:" + end);
Console.WriteLine ("\nfind best contiguous total: " + arr.HighestContiguousSum(arr2,out start, out end) + "start:"+ start + "end:" + end);
Console.WriteLine ("\n2 largest: " + arr.sumTwoLargest (arr2));
Console.WriteLine("\nsum 3 largest: " + arr.sumNLargest(arr2,3));
}