二叉树的生成-创新互联
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections.Generic; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { personalInfo p1 = new personalInfo("1", "1"); personalInfo p2 = new personalInfo("2", "2"); personalInfo p3 = new personalInfo("3", "3"); personalInfo p4 = new personalInfo("", ""); personalInfo p31 = new personalInfo("31", "31"); personalInfo p32 = new personalInfo("32", "32"); personalInfo p33 = new personalInfo("", ""); personalInfo p321 = new personalInfo("", ""); personalInfo p311 = new personalInfo("", ""); personalInfo p21 = new personalInfo("", ""); personalInfo p11 = new personalInfo("11", "11"); personalInfo p12 = new personalInfo("", ""); personalInfo p111 = new personalInfo("", ""); List成都创新互联于2013年创立,先为城厢等服务建站,城厢等地企业,进行企业商务咨询服务。为城厢企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。list = new System.Collections.Generic.List (); list.AddRange(new personalInfo[]{p1,p2,p3,p4,p31,p32,p33,p321,p311,p21,p11,p12,p111}); JiaPu j = new JiaPu(list); note phead = null; int index = j.CreateTree(ref phead, 0, 13); } public struct personalInfo { public personalInfo(string name, string Id) { this.name = name; this.Id = Id; } public string name; public string Id; // Id is empty or null, that means, no the person. } public class note { public personalInfo data; public note lChild, rChild; } public class JiaPu { List persons; // int index = 0; public JiaPu(List persons) { this.persons = persons; } public int CreateTree(ref note nNode,int index, int length) { if(index>=length) { nNode= null; return index; } if (string.IsNullOrEmpty(persons[index].Id)) { nNode = null; return index; } nNode = new note(); nNode.data = persons[index]; index = CreateTree(ref nNode.lChild, ++index, length); index = CreateTree(ref nNode.rChild, ++index, length); return index; } } } }
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
文章名称:二叉树的生成-创新互联
链接URL:http://myzitong.com/article/cdgcce.html