• 当前位置:首页>>VB程序设计>>VB数据库和文件访问>>应用数据结构(一)线性表节点的插入和删除算法
  • 应用数据结构(一)线性表节点的插入和删除算法

  • snowcloud2002(原作)
    线性表节点的插入和删除算法

    '作者:Snowcloud2002
    '插入节点
    '函数名称: NodeInsert(Pos As Integer, Num As Integer, TableName As Variant) As Boolean
    '参数: Pos As Integer要插入节点的位置,Num As Integer要插入的数值,TableName As Variant线性表名称
    '返回值: Boolean

    Function NodeInsert(Pos As Integer, Num As Integer, TableName As Variant

    '改变源线性表长度:插入结点后线性表长度加一
    ReDim Preserve TableName(UBound(TableName) + 1)
    '对线性表中第i个元素到最后一个元素的位置后移一位
    For i = (UBound(TableName)) To (Pos + 1) Step -1
    If i < 1 Or i > (UBound(TableName)) Then
    Insert = False
    Exit Function
    Else
    TableName(i) = TableName(i - 1)
    End If
    Next
    '将要插入的元素放到第i个位置
    TableName(i) = Num
    Insert = True
    End Function

    '删除节点
    '函数名称: NodeDelete(Pos As Integer, TableName As Variant) As Boolean
    '参数: Pos As Integer要删除节点的位置,TableName as Variant线性表名称

    '返回值: Boolean
    Function NodeDelete(Pos As Integer, TableName As Variant) As Boolean
    '对线性表中第i个元素到最后一个元素的位置前移一位
    For i = Pos To (UBound(TableName))
    If i < 1 Or i > (UBound(TableName)) Then
    Delete = False
    Exit Function
    Else
    TableName(i - 1) = TableName(i)
    End If
    Next
    '改变源线性表长度:删除结点后线性表长度减一
    ReDim Preserve TableName(UBound(TableName) - 1)
    Delete = True
    End Function

  • 上一篇:Crystal Report(水晶报表)的报表封装成VB的DLL
    下一篇:用 DAO 或 ADO 正确访问 Access 2000