zoukankan      html  css  js  c++  java
  • 线性表节点的插入和删除算法

     

    '原作者: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

  • 相关阅读:
    允许debian wheezy支持IOS7+的iphone.
    openSUSE 国内镜像摘要
    策略模式总结
    顺序串
    WindowState注意事项
    NLP | 自然语言处理
    Using Autorelease Pool Blocks
    NSAutoreleasePool & thread
    oc语言特性
    oc语言基础整理
  • 原文地址:https://www.cnblogs.com/topboy168/p/460388.html
Copyright © 2011-2022 走看看