Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Looking for duplicates..

Posted on 2011-05-09
4
Medium Priority
?
208 Views
Last Modified: 2012-05-11
Idle_Mind, you are right but I am not sure how to implement it.

I will create new question, can u help in the next one?  I understand i can find duplicates keys but what If I have:

1000,2000,0001,0004,0010,0050
and
1000,2000,0000,0003,0020,0060

both are not duplicate but it should still fail because from 0000 to 0003 there is 0001 and 0002 and 0003 inside it already in the first line (between 0001 and 0004)

do you have time for a little code?
0
Comment
Question by:PhilippeRenaud
  • 2
  • 2
4 Comments
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 35725304
In other words, did you mean that by "collisions"?
0
 
LVL 28

Expert Comment

by:Ark
ID: 35725772

Public Class Numbers
    Private m_List As New List(Of Point)
    Private minVal As Integer = 0
    Private maxVal As Integer = 990

    Public Function AddPair(ByVal pFrom As Integer, ByVal pTo As Integer) As Boolean
        If pFrom >= pTo Then
            MsgBox("pFrom >= pTo")
            Return False
        End If
        If Not IsBetween(pFrom, minVal, maxVal) Then
            MsgBox("pFrom not in limits")
            Return False
        End If
        If Not IsBetween(pTo, minVal, maxVal) Then
            MsgBox("pTo not in limits")
            Return False
        End If
        For i As Integer = 0 To m_List.Count - 1
            Dim p As Point = m_List(i)
            If IsBetween(pFrom, p.X, p.Y) Then
                MsgBox(String.Format("pFrom {0} already exists in row {1} from {2} to {3}", pFrom, i, p.X, p.Y))
                Return False
            ElseIf IsBetween(pTo, p.X, p.Y) Then
                MsgBox(String.Format("pTo {0} already exists in row {1} from {2} to {3}", pTo, i, p.X, p.Y))
                Return False
            End If
        Next
        m_List.Add(New Point(pFrom, pTo))
        Return True
    End Function

    Public ReadOnly Property List() As List(Of Point)
        Get
            Return m_List
        End Get
    End Property

    Private Function IsBetween(ByVal value As Integer, ByVal min As Integer, ByVal max As Integer) As Boolean
        Return (value >= min AndAlso value <= max)
    End Function
End Class

Open in new window

0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 35726039
did you test it  with values?
0
 
LVL 28

Accepted Solution

by:
Ark earned 2000 total points
ID: 35726370

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim num As New Numbers
        num.AddPair(1000, 2000)
        num.AddPair(1, 4)
        num.AddPair(10, 50)
        num.AddPair(1000, 2000)
        num.AddPair(0, 3)
        num.AddPair(20, 60)
    End Sub
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Integration Management Part 2
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month21 days, 1 hour left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question