Sorting an array in ASP

Results 1 to 2 of 2

Thread: Sorting an array in ASP

  1. #1
    todw17 Guest

    Default Sorting an array in ASP

    I am trying to sort an array in ASP. I only have 30 values tops, with a range from 0 to 100. I tried implementing SelectionSort, but I couldnt get that to work. As of right now, this is the code I have:<BR><BR>&#060;%<BR> Dim myArray(9), counter, insertCounter<BR><BR> Function Sort(ary)<BR> Dim KeepChecking, I, FirstValue, SecondValue<BR><BR> KeepChecking = TRUE<BR> Do Until KeepChecking = FALSE<BR> KeepChecking = FALSE<BR> For I = 0 to UBound(ary)<BR> If I = UBound(ary) Then Exit For<BR> If ary(I) &#062; ary(I+1) Then<BR> FirstValue = ary(I)<BR> SecondValue = ary(I+1)<BR> ary(I) = SecondValue<BR> ary(I+1) = FirstValue<BR> KeepChecking = TRUE<BR> End If<BR> Next<BR> Loop<BR> Sort = ary<BR> END Function<BR> <BR> insertCounter = 0 <BR> counter = 0<BR> WHILE Not counter &#062; 9<BR> myArray(counter) = 100 - (counter * 10)<BR> Response.Write myArray(counter) & "<BR>" & vbCrLf<BR> insertCounter = insertCounter + 1<BR> counter=counter + 1<BR> WEnd<BR> Response.Write "Hello" & vbCrLF<BR> <BR> myArray = Sort(myArray)<BR> <BR> WHILE Not counter &#062; 9<BR> Response.Write myArray(counter) & "<BR>" & vbCrLf<BR> counter=counter + 1<BR> WEnd<BR>%&#062;<BR><BR>If anyone has any suggestions, or sorting algorithms that might work, I&#039;d appreciate the help.

  2. #2
    Join Date
    Dec 1969

    Default Sorting Array article in

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts