考勤正班时间数组(数组个数为2的倍数,最长有9个时间段):
arrTime(0) = 08:00
arrTime(1) = 12:00arrTime(2) = 14:00
arrTime(3) = 18:00

现在有一个加班时间段,例如 12:30-13:30 
加班时间段需要按时间顺序插入以上数组中,形成以下数组:
arrTime(0) = 08:00
arrTime(1) = 12:00arrTime(2) = 12:30
arrTime(3) = 13:30arrTime(4) = 14:00
arrTime(5) = 18:00

加班时间段是不确定的,考勤正班时间数组的时间段也是不确定的,
如何写一段算法能将加班时间段插入到数组的正确位置上。注意:加班时间段是不会与正班时间段重合的。

解决方案 »

  1.   

    rainstormmaster(暴风雨 v2.0):
       能不能劳驾你帮我写一个效率最高的算法呢。
      

  2.   

    不用数组嘛。用 Collection(集合)想放多少就放多少
      

  3.   

    用 Collection(集合),因为可以在指定的位置插入新的成员
       colTime.add time33 , , 4
    Collection(集合)还可以删除指定位置的成员
       colTime.remove,3
      

  4.   

    Sub inserttime(ByVal period As String, ByRef arrtime() As String)
    Dim TEMP1 As String, TEMP2 As String, TEMP As Integer, I As Integer, MAX As Integer
    TEMP1 = Trim(Split(period, "-")(0))
    TEMP2 = Trim(Split(period, "-")(1))
    MAX = UBound(arrtime)
    For I = 1 To MAX - 1
    If TEMP1 > arrtime(I - 1) Then TEMP = I
    NextIf TEMP2 < arrtime(0) Then TEMP = 0
    If TEMP1 > arrtime(MAX) Then TEMP = MAXReDim Preserve arrtime(MAX + 2)For I = MAX + 2 To TEMP + 2 Step -1
    arrtime(I) = arrtime(I - 2)
    Nextarrtime(TEMP + 1) = TEMP2
    arrtime(TEMP) = TEMP1End Sub
    Private Sub Command1_Click()
    Dim arrtime() As String, I As Integer
    ReDim arrtime(3)
    arrtime(0) = "08:00"
    arrtime(1) = "12:00"arrtime(2) = "14:00"
    arrtime(3) = "18:00"MsgBox Join(arrtime, vbCrLf)
    inserttime "12:30-13:30", arrtime
    MsgBox Join(arrtime, vbCrLf)
    End Sub
      

  5.   

    谢谢northwolves(狼行天下),有没有其他的朋友再写写其他的算法,让我好有一个比较。Zygodactyous(Zygodactyous) :
    暂时不考虑休息日加班的情况
      

  6.   

    数据不多,怎么排序也可以。
    数据多可以考虑使用 COPYMEMORY 移动数组
    也可以用LISTBOX 实现'add a listbox(sort=true) and a commandbutton to form1:Dim arrtime() As String
    Private Sub Command1_Click()
    Dim I As Integer
    List1.AddItem Split("12:30-13:30", "-")(0)
    List1.AddItem Split("12:30-13:30", "-")(1)
    ReDim arrtime(List1.ListCount - 1)
    For I = 0 To List1.ListCount - 1
    arrtime(I) = List1.List(I)
    Next
    'MsgBox Join(arrtime, vbCrLf)
    End SubPrivate Sub Form_Load()
    Dim I As Integer
    ReDim arrtime(3)
    arrtime(0) = "08:00"
    arrtime(1) = "12:00"
    arrtime(2) = "14:00"
    arrtime(3) = "18:00"
    For I = 0 To UBound(arrtime)
    List1.AddItem arrtime(I)
    Next
    End Sub