Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
646
|
Chapter 11: Data Structures and Algorithms
topLevel.DepthFirstSearch(b): b
topLevel.DepthFirstSearch(c): c
topLevel.DepthFirstSearch(d): d
topLevel.DepthFirstSearch(e): e
topLevel.DepthFirstSearch(f): f
d
Contains Left: NULL
Contains Right: f
e
Contains Left: NULL
Contains Right: NULL
f
Contains Left: e
Contains Right: g
g
Contains Left: NULL
Contains Right: NULL
d
Contains Left: NULL
Contains Right: NULL
See Also
See the “Queue Class” and “IComparable<T> Interface” topics in the MSDN docu-
mentation.
11.7 Creating an n-ary Tree
Problem
You need a tree that can store a number of child nodes in each of its nodes. A binary
tree will work if each node needs to have only two children, but in this case each
node needs to have a fixed number of child nodes greater than two.
Solution
Use the NTree<T> class shown in Example 11-14 to create the root node for the n-ary
tree.
Example 11-14. Generic NTree class
using System;
using System.Collections;
using System.Collections.Generic;
public class NTree<T> : IEnumerable<T>
where T : IComparable<T>
{
public NTree( )
{
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Creating an n-ary Tree
|
647
The ...
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

C# Cookbook

C# Cookbook

Joe Mayo
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata