Traversing a tree of objects in c#

前端 未结 2 1499
时光说笑
时光说笑 2020-12-02 11:19

I have a tree that consists of several objects, where each object has a name (string), id (int) and possibly an array of children that are of the s

2条回答
  •  北海茫月
    2020-12-02 12:01

    Well, you could always use recursion, but in a "real world" programming scenario, it can lead to bad things if you don't keep track of the depth.

    Here's an example used for a binary tree: http://www.codeproject.com/KB/recipes/BinarySearchTree.aspx

    I would google linked lists and other tree structures if you're new to the whole data structure thing. There's a wealth of knowledge to be had.

提交回复
热议问题