Arrange points in increased order of X

Discussion in 'AutoCAD' started by irfan, Feb 4, 2005.

  1. irfan

    irfan Guest

    I have a set of points in an array. I need to arrange those points in increased order of their X value(element 0), so that i can dimension them as dimContinue

    InputArray = {{2,0,0},{1,0,0},{6,0,0}}
    outputArray = {{1,0,0},{2,0,0},{6,0,0}}

    Has any body got any idea how to it.

    TIA
    Irfan
     
    irfan, Feb 4, 2005
    #1
  2. Irfan, Do a search for Sort methods if this doesn't
    help. "Quick Sort", "Bubble Sort" and others, depending
    on the size of your List, some are quicker than others.

    gl
    Paul

    'Call to function. XP is a variant array of your values
    BubbleSortVariantArray XP

    'Bubble Sort Function, one of many...Could add Option of
    'Sorting High to Low / Low to High
    Public Sub BubbleSortVariantArray(avarIn() As Variant)
    ' Comments : Bubble-sorts the passed variant array
    ' Parameters: avarIn() array of variants
    ' Returns : Nothing

    Dim intLowBounds As Integer
    Dim intHighBounds As Integer
    Dim intX As Integer
    Dim intY As Integer
    Dim varTmp As Variant

    On Error GoTo PROC_ERR

    ' Get the bounds of the array
    intLowBounds = LBound(avarIn)
    intHighBounds = UBound(avarIn)

    ' For each element in the array
    For intX = intLowBounds To intHighBounds - 1
    ' for each element in the array
    For intY = intX + 1 To intHighBounds
    ' If a value lower in the array is
    'greater than a values higher in the
    ' array, swap them
    If avarIn(intX) > avarIn(intY) Then
    varTmp = avarIn(intX)
    avarIn(intX) = avarIn(intY)
    avarIn(intY) = varTmp
    End If

    Next intY

    Next intX

    PROC_EXIT:
    Exit Sub

    PROC_ERR:
    MsgBox "Error: " & Err.Number & ". " & Err.Description, , _
    "BubbleSortVariantArray"
    Resume PROC_EXIT

    End Sub
     
    Paul Richardson, Feb 4, 2005
    #2
  3. irfan

    irfan Guest

    many thanks Paul,
     
    irfan, Feb 4, 2005
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.