资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

关于vb.net无参数递归的信息

有没有朋友可以详细解释一下关于VB.NET里面的递归?最好有代码加注释,谢谢.

给你个例子希望可以帮到你

创新互联主营中原网站建设的网络公司,主营网站建设方案,app软件开发公司,中原h5微信小程序定制开发搭建,中原网站营销推广欢迎中原等地区企业咨询

递归系统目录结构.

递归整个C盘目录:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim iDir As IO.Directory

Dim node As New TreeNode

'先把C盘添加到树中

TreeView1.Nodes.Clear()

node.ImageIndex = 0

node.Text = "本地磁盘 C:"

node.SelectedImageIndex = -1

TreeView1.Nodes.Add(node)

Dim i As Integer

'获取C:盘根目录下的文件夹

Dim str() As String = IO.Directory.GetDirectories("D:\")

For i = 0 To str.GetUpperBound(0)

'调用遍历过程

AddDirectory("C:", str(i), node)

Next

node = Nothing

iDir = Nothing

End Sub

Public Sub AddDirectory(ByVal strFatherPath As String, ByVal strPath As String, ByVal nodeFather As TreeNode)

Dim iDir As IO.Directory

'Dim iDirInfo As IO.DirectoryInfo

Dim i As Integer

Dim node As New TreeNode

'先添加本目录,从文件夹路径分析出文件夹名称

node.Text = Strings.Replace(strPath, strFatherPath "\", "", , 1)

'为单个节点指定节点未被选中时显示的图标

node.ImageIndex = 1

'为单个节点指定节点被选中时显示的图标

node.SelectedImageIndex = 2

nodeFather.Nodes.Add(node)

Application.DoEvents()

Try

Dim str() As String = IO.Directory.GetDirectories(strPath)

'遍历该目录的子文件夹

For i = 0 To str.GetUpperBound(0)

AddDirectory(strPath, str(i), node)

Next

Catch ex As Exception

Debug.WriteLine(ex.Message)

End Try

node = Nothing

iDir = Nothing

End Sub

vb.net 递归 vb.net 递归

这种不要用递归,知道关键字长度,知道节数用判断就可以了,取前3位第一节,第二节取3个为父节点,取全部为第二节关键字,第三节取前6个为父节点,取全部为第三节关键字.

并没有要求培养字段,查询时从len(ID)=3*N,每次循环时N都+1

select * from tablename where len(id)=3

select case N

case 1

treeview.node.add id,name

case 2

treeview.node(left(id,3)).node.add id,name

case 3

treeview.node(left(id,3)).node(left(id,6)).add id,name

end select

查询结果排个升序就不会存在这样的问题了,你刚才说的那种,如果中间没有比001001001001001更短的关键字,那么就脱节,这种是不可能添加到treeview中.

递归一般用在不知道节数,没有关键字的情况,比如系统目录结构.

递归整个C盘目录:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim iDir As IO.Directory

Dim node As New TreeNode

'先把C盘添加到树中

TreeView1.Nodes.Clear()

node.ImageIndex = 0

node.Text = "本地磁盘 C:"

node.SelectedImageIndex = -1

TreeView1.Nodes.Add(node)

Dim i As Integer

'获取C:盘根目录下的文件夹

Dim str() As String = IO.Directory.GetDirectories("D:\")

For i = 0 To str.GetUpperBound(0)

'调用遍历过程

AddDirectory("C:", str(i), node)

Next

node = Nothing

iDir = Nothing

End Sub

Public Sub AddDirectory(ByVal strFatherPath As String, ByVal strPath As String, ByVal nodeFather As TreeNode)

Dim iDir As IO.Directory

'Dim iDirInfo As IO.DirectoryInfo

Dim i As Integer

Dim node As New TreeNode

'先添加本目录,从文件夹路径分析出文件夹名称

node.Text = Strings.Replace(strPath, strFatherPath "\", "", , 1)

'为单个节点指定节点未被选中时显示的图标

node.ImageIndex = 1

'为单个节点指定节点被选中时显示的图标

node.SelectedImageIndex = 2

nodeFather.Nodes.Add(node)

Application.DoEvents()

Try

Dim str() As String = IO.Directory.GetDirectories(strPath)

'遍历该目录的子文件夹

For i = 0 To str.GetUpperBound(0)

AddDirectory(strPath, str(i), node)

Next

Catch ex As Exception

Debug.WriteLine(ex.Message)

End Try

node = Nothing

iDir = Nothing

End Sub

编写递归函数,函数只有一个参数(整数类型)比如参数=10,那么靠自己调用自己,将10到1进行累加,并返回

int nestAdd(int n) {

if (n 1) return n + nestAdd(n - 1);

else return n;

}

简述vb.net过程的嵌套调用和递归调用

嵌套是指一个过程调用另一个过程的使用,递归过程是这个过程中调用本过程的使用。递归是嵌套的一种特殊形式,递归过程必须有“归点”,也就是终止调用本身的一个分支


当前文章:关于vb.net无参数递归的信息
网站网址:http://cdkjz.cn/article/docsggg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220