应用数据结构(一)线性表节点的插入和删除算法

<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

线性表节点插入删除算法

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

===============================================
欢迎大家发表看法,有问题的地方大家请指正,谢谢!
===============================================

 

<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
阅读更多
个人分类: vb
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭