Skip to Content
C# Data Structures and Algorithms
book

C# Data Structures and Algorithms

by Marcin Jamro
April 2018
Intermediate to advanced content levelIntermediate to advanced
292 pages
6h 44m
English
Packt Publishing
Content preview from C# Data Structures and Algorithms

Node

Let's start with the class representing a single node in a tree. Fortunately, you can use the implementation of the class already described for the binary tree (BinaryTreeNode) as a base. The modified code is as follows:

public class BinaryTreeNode<T> : TreeNode<T> { public BinaryTreeNode() => Children = new List<TreeNode<T>>() { null, null }; public BinaryTreeNode<T> Parent { get; set; } public BinaryTreeNode<T> Left { get { return (BinaryTreeNode<T>)Children[0]; } set { Children[0] = value; } } public BinaryTreeNode<T> Right { get { return (BinaryTreeNode<T>)Children[1]; } set { Children[1] = value; } } public int GetHeight() { int height = 1; BinaryTreeNode<T> current = this; while (current.Parent != null) { height++; current = current.Parent; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Data Structures and Algorithms in C#

Beginning Data Structures and Algorithms in C#

Marcin Jamro

Publisher Resources

ISBN: 9781788833738Supplemental Content