i am copying array a and array b to array c.
the only problem is i don't want duplicate numbers?
i tried doing this by looping array c and when a duplicate is found put a zero there but what i
actually wanted to do is delete the element instead, and shift the array up.
i also found that for some reason the number 11 still show's up twice?
Thank you,
Dim a() As Double = {1, 2, 3, 4, 5, 6, 7, 7, 9, 10, 11, 11, 13, 14, 15, 16, 17, 18, 19, 20}
Dim b() As Double = {1, 2, 3, 4, 5, 6, 7, 7, 9, 10, 11, 11, 13, 14, 15, 16, 17, 18, 19, 20}
Dim c() As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim indexA, indexB As Integer
Dim doneA, doneB As Boolean
'Merge ascending arrays, with duplications.
ReDim c(39)
indexA = 0
indexB = 0
doneA = False
doneB = False
'Loop over each element of the resulting array.
For indexC As Integer = 0 To 39
'If a's element is less than b's, add a's to c.
If ((a(indexA) <= b(indexB)) And Not doneA) Or (doneB) Then
c(indexC) = a(indexA)
'Get next element from a.
If indexA < 19 Then
indexA = indexA + 1
Else
doneA = True
End If
Else
'Otherwise, add b's element to c.
c(indexC) = b(indexB)
'Get next element from b
If indexB < 19 Then
indexB = indexB + 1
Else
doneB = True
End If
End If
Next
Dim flag, i, count As Integer
flag = 0
count = 0
For i = 0 To c.GetUpperBound(0) - 1
If flag = 0 Then
If (c(i) = c(i + 1)) Then
c(i + 1) = 0
'if a duplicate is found but a 0 in that position
flag = 1
End If
Else
If (c(i) <> c(i + 1)) Then
flag = 0
End If
End If
Next
For k As Integer = 0 To 39
lstout.Items.Add(c(k))
Next
End Sub
End Class

New Topic/Question
Reply




MultiQuote





|