VB冒泡排序

//先按照LocationNo排序,再按照DNNoDNItemNo排序
Private Sub Sort(ByVal boxList As IList(Of ShippingServiceDTO.SuggestionBox))
        Dim locationNo As String = ""
        Dim boxNo As String = ""
        Dim fIDNo As String = ""
        Dim mLFB As String = ""
        Dim quantity As String = ""
        Dim status As String = ""
        Dim dNNoDNItemNo As String = ""
        Dim rExChange As Integer

        For i As Integer = 0 To boxList.Count - 1
            For j As Integer = i + 1 To boxList.Count - 1
                rExChange = SortContext(boxList(i).LocationNo, boxList(j).LocationNo)
                If (rExChange = 0) Then
                    rExChange = SortContext(boxList(i).DNNoDNItemNo, boxList(j).DNNoDNItemNo)
                End If
                If (rExChange = 1) Then
                    locationNo = boxList(j).LocationNo
                    boxNo = boxList(j).BoxNo
                    fIDNo = boxList(j).FIDNo
                    mLFB = boxList(j).MLFB
                    quantity = boxList(j).Quantity
                    status = boxList(j).Status
                    dNNoDNItemNo = boxList(j).DNNoDNItemNo

                    boxList(j).LocationNo = boxList(i).LocationNo
                    boxList(j).BoxNo = boxList(i).BoxNo
                    boxList(j).FIDNo = boxList(i).FIDNo
                    boxList(j).MLFB = boxList(i).MLFB
                    boxList(j).Quantity = boxList(i).Quantity
                    boxList(j).Status = boxList(i).Status
                    boxList(j).DNNoDNItemNo = boxList(i).DNNoDNItemNo

                    boxList(i).LocationNo = locationNo
                    boxList(i).BoxNo = boxNo
                    boxList(i).FIDNo = fIDNo
                    boxList(i).MLFB = mLFB
                    boxList(i).Quantity = quantity
                    boxList(i).Status = status
                    boxList(i).DNNoDNItemNo = dNNoDNItemNo
                End If
            Next
        Next
    End Sub

    Private Function SortContext(ByVal strI As String, ByVal strJ As String) As String
        Dim iCount As Integer
        Dim arri() As Char
        Dim arrj() As Char
        Dim rExChange As Integer
        arri = strI.ToCharArray()
        arrj = strJ.ToCharArray()
        If (arri.Length < arrj.Length) Then
            iCount = arri.Length
        Else
            iCount = arrj.Length
        End If
        For m As Integer = 0 To iCount - 1
            If (arri(m) > arrj(m)) Then
                rExChange = 1
                Exit For
            End If
            If (arri(m) < arrj(m)) Then
                rExChange = -1
                Exit For
            End If
            If (arri(m) = arrj(m)) Then
                rExChange = 0
            End If
        Next
        If (rExChange = 0) Then
            If (arri.Length > arrj.Length) Then
                rExChange = 1
            End If
            If (arri.Length < arrj.Length) Then
                rExChange = -1
            End If
        End If
        Return rExChange
    End Function
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值