一个关于递归的示例
来源:互联网 发布:龙芯linux计算机编程 编辑:程序博客网 时间:2024/06/03 13:09
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace SortApplication
{
public class getList
{
public int id;
public int parentId;
public string name;
public getList(int id, int parentId, string name)
{
this.id = id;
this.parentId = parentId;
this.name = name;
}
}
class Program
{
private static IList<getList> GetList(getList[] myList, int pid)
{
int count = myList.Length;
IList<getList> al = new List<getList>();
for (int i = 0; i < count; i++)
{
if (myList[i].parentId == pid)
{
// Console.WriteLine(”上面测试 : ” + pid);
al.Add(myList[i]);
}
}
return al;
}
private static void SortList(getList[] myList, IList<getList> Al, ref getList[] listCopy)
{
if (listCopy[0] == null)
{
Al.Add(myList[0]);
}
try
{
foreach (getList lis in Al)
{
int i;
for (i = 0; i < listCopy.Length; i++)
{
if (listCopy[i] == null)
{
break;
}
}
// Console.WriteLine("///" + i + "//////");
listCopy[i] = (getList)lis;
// Console.WriteLine(f);
Al = GetList(myList, lis.id);
SortList(myList, Al, ref listCopy);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
static void Main(string[] args)
{
getList[] ourList = new getList[] {
new getList(1, 0, "a"),
new getList(2, 1, "b"),
new getList(3, 1, "c"),
new getList(4, 2, "d"),
new getList(5, 4, "e"),
new getList(7, 3, "aaa"),
new getList(6, 5, "f")
};
string BlankBase = new string(' ', 8);
Console.WriteLine("排序以前的对象");
for (int i = 0; i < ourList.Length; i++)
{
Console.WriteLine(ourList[i].id + BlankBase + ourList[i].parentId + BlankBase + ourList[i].name);
}
getList[] listCopy = new getList[ourList.Length];
IList<getList> Alist = new List<getList>();
SortList(ourList, Alist, ref listCopy);
Console.WriteLine("\r\n\r\n排序以后的对象");
for (int i = 0; i < listCopy.Length; i++)
{
try
{
Console.WriteLine(listCopy[i].id + BlankBase + listCopy[i].parentId + BlankBase + listCopy[i].name);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
}
- 一个关于递归的示例
- 一个关于递归的示例
- C/C++:递归的一个简单示例
- 关于递归的一个例子
- 关于图的一个小递归
- 一个关于矩阵的递归问题
- PLSQL中关于包的一个示例
- 关于java初始化顺序的一个示例
- 关于java发送邮件的一个示例
- 关于JavaScript面向对象的一个示例
- 递归的典型示例
- 关于一个递归逻辑的代码优化建议
- 递归及生成器的示例
- 一个关于css中图片相对路径引用的示例
- 关于 javascript 中 继承的 一个 小 示例
- C语言一个关于文件操作的示例
- 关于多线程出现安全问题的一个小示例
- 递归的一个实例
- Linux_输出文件的某列or某几列_cut_-f
- Ogre1.7.x中使用CEGUI的变化
- 操作系统内存管理
- jsp页面dreamweaver中正常,myeclipse中乱码
- 2012-04-20
- 一个关于递归的示例
- 工作后,如何免费查论文
- createSQLQuery与createQuery的区别
- (jenkins)hudson平台搭建android项目持续化集成以及基于NativeDriver的自动化测试环境
- Context 传递数据
- MFC添加自定义消息
- OMA的IM三种模式
- SqlDataReader 与 DataSet读取sql中的数据
- 三层架构