////////////////////////
//Tree
///////////////////////
using System;
using System.Collections;namespace SampleTree
{
public class TreeNode
{
#region The TreeNodeCollection class.
public class TreeNodeCollection:ICollection
{
private TreeNode _owner=null;
private ArrayList _innerList=new ArrayList(); public TreeNodeCollection(TreeNode owner)
{
this._owner=owner;
}
public TreeNode this[int index]
{
get{return (TreeNode)this._innerList[index];}
set
{
if(value ==null)
throw new ArgumentNullException();
(this._innerList[index] as TreeNode)._parent=null;;
value._parent=this._owner;
this._innerList[index]=value;
}
}
public bool IsSynchronized
{
get{ return this._innerList.IsSynchronized;}
}
public int Count
{
get{ return this._innerList.Count;}
}
public void CopyTo(Array array, int index)
{
this._innerList.CopyTo(array,index);
}
public object SyncRoot
{
get
{
return this._innerList.SyncRoot;
}
}
public IEnumerator GetEnumerator()
{
return this._innerList.GetEnumerator();
} public int Add(TreeNode value)
{
if(value ==null)
throw new ArgumentNullException();
value._parent=this._owner;
return this._innerList.Add(value);
} public void Insert(int index, TreeNode value)
{
if(value ==null)
throw new ArgumentNullException();
value._parent=this._owner;
this._innerList.IndexOf(value,index);
} public void RemoveAt(int index)
{
try
{
this[index]._parent=null;
this._innerList.RemoveAt(index);
}
catch
{
}
}
public int IndexOf(TreeNode value)
{
return this._innerList.IndexOf(value);
}
public void Clear()
{
for(int i=0;i<this.Count;i++)
{
this[i]._parent=null;
}
this._innerList.Clear();
}
public bool Contains(TreeNode value)
{
return this._innerList.Contains(value);
}
}
#endregion
private TreeNode _parent=null;
private string _value=null;
private TreeNodeCollection _childNodes=null; public TreeNode(string value)
{
this._value=value;
}
public TreeNode ParentNode
{
get{return this._parent;}
}
public string Value
{
get{return this._value;}
}
public TreeNodeCollection ChildNodes
{
get
{
if(this._childNodes !=null) return this._childNodes;
this._childNodes=new TreeNodeCollection(this);
return this._childNodes;
}
}
public bool IsRoot
{
get{return this.ParentNode==null;}
}
public bool IsLeaf
{
get
{
return this._childNodes==null || this._childNodes.Count==0;
}
}
public string Location
{
get
{
string location=string.Empty;
TreeNode treeNode=this;
while(treeNode.ParentNode!=null)
{
treeNode=treeNode.ParentNode;
location=treeNode.Value+@"|"+location;
}
return this.Location;
}
}
}
public class Tree
{
private TreeNode.TreeNodeCollection _nodes=new TreeNode.TreeNodeCollection(null); public TreeNode.TreeNodeCollection Nodes
{
get{return this._nodes;}
}
public TreeNode SearchNode(string location)
{
string[] loc=location.Split(new char[]{'|'});
if(loc.Length==0) return null;
TreeNode treeNode=null;
for(int i=0;i<this.Nodes.Count;i++)
{
if(this.Nodes[i].Value==loc[0])
{
treeNode=this.Nodes[i]; break;
}
}
int c=1;
while(treeNode!=null && c<loc.Length)
{
for(int i=0;i<treeNode.ChildNodes.Count;i++)
{
if(treeNode.ChildNodes[i].Value==loc[c])
{
treeNode=treeNode.ChildNodes[i];
c++;
}
}
treeNode=null;
}
return treeNode;
}
}
}
//Tree
///////////////////////
using System;
using System.Collections;namespace SampleTree
{
public class TreeNode
{
#region The TreeNodeCollection class.
public class TreeNodeCollection:ICollection
{
private TreeNode _owner=null;
private ArrayList _innerList=new ArrayList(); public TreeNodeCollection(TreeNode owner)
{
this._owner=owner;
}
public TreeNode this[int index]
{
get{return (TreeNode)this._innerList[index];}
set
{
if(value ==null)
throw new ArgumentNullException();
(this._innerList[index] as TreeNode)._parent=null;;
value._parent=this._owner;
this._innerList[index]=value;
}
}
public bool IsSynchronized
{
get{ return this._innerList.IsSynchronized;}
}
public int Count
{
get{ return this._innerList.Count;}
}
public void CopyTo(Array array, int index)
{
this._innerList.CopyTo(array,index);
}
public object SyncRoot
{
get
{
return this._innerList.SyncRoot;
}
}
public IEnumerator GetEnumerator()
{
return this._innerList.GetEnumerator();
} public int Add(TreeNode value)
{
if(value ==null)
throw new ArgumentNullException();
value._parent=this._owner;
return this._innerList.Add(value);
} public void Insert(int index, TreeNode value)
{
if(value ==null)
throw new ArgumentNullException();
value._parent=this._owner;
this._innerList.IndexOf(value,index);
} public void RemoveAt(int index)
{
try
{
this[index]._parent=null;
this._innerList.RemoveAt(index);
}
catch
{
}
}
public int IndexOf(TreeNode value)
{
return this._innerList.IndexOf(value);
}
public void Clear()
{
for(int i=0;i<this.Count;i++)
{
this[i]._parent=null;
}
this._innerList.Clear();
}
public bool Contains(TreeNode value)
{
return this._innerList.Contains(value);
}
}
#endregion
private TreeNode _parent=null;
private string _value=null;
private TreeNodeCollection _childNodes=null; public TreeNode(string value)
{
this._value=value;
}
public TreeNode ParentNode
{
get{return this._parent;}
}
public string Value
{
get{return this._value;}
}
public TreeNodeCollection ChildNodes
{
get
{
if(this._childNodes !=null) return this._childNodes;
this._childNodes=new TreeNodeCollection(this);
return this._childNodes;
}
}
public bool IsRoot
{
get{return this.ParentNode==null;}
}
public bool IsLeaf
{
get
{
return this._childNodes==null || this._childNodes.Count==0;
}
}
public string Location
{
get
{
string location=string.Empty;
TreeNode treeNode=this;
while(treeNode.ParentNode!=null)
{
treeNode=treeNode.ParentNode;
location=treeNode.Value+@"|"+location;
}
return this.Location;
}
}
}
public class Tree
{
private TreeNode.TreeNodeCollection _nodes=new TreeNode.TreeNodeCollection(null); public TreeNode.TreeNodeCollection Nodes
{
get{return this._nodes;}
}
public TreeNode SearchNode(string location)
{
string[] loc=location.Split(new char[]{'|'});
if(loc.Length==0) return null;
TreeNode treeNode=null;
for(int i=0;i<this.Nodes.Count;i++)
{
if(this.Nodes[i].Value==loc[0])
{
treeNode=this.Nodes[i]; break;
}
}
int c=1;
while(treeNode!=null && c<loc.Length)
{
for(int i=0;i<treeNode.ChildNodes.Count;i++)
{
if(treeNode.ChildNodes[i].Value==loc[c])
{
treeNode=treeNode.ChildNodes[i];
c++;
}
}
treeNode=null;
}
return treeNode;
}
}
}
解决方案 »
- 讲一LINQ 讲列按照 1,2,3,4 编号
- 谁有TFS2010 64位 还有DxExpress7.2
- c# 如何动态调用如下dll?
- 哪位大虾来帮我看下这段代码中哪里有问题。
- 关于串口编程的小问题
- 怎么将一blob字段内容上传下载到文件,高分在线等!!!
- C# 中工具条怎样添加上图标??
- 哪里可以提供类似coolbar这种有控制条得toolbar?vs里面有么?
- 哪位兄弟帮我一把,小问题100分,解决了开贴再送
- vs。winfrom如何实现输入注册码的textbox
- 在水晶报表里面添加了几个TextOject,在Viewer可以看到,但打印出来就不见了
- C#中有类似PB的EditMask输入控件吗?
像C++链表的
class node
{
int data;
node* next;
}
在C#里只要写成
class node
{
int data;
node next;
}
就可以了。