www.webdeveloper.com
Results 1 to 13 of 13

Thread: is there sort command n vbscript?

  1. #1
    Join Date
    Jan 2003
    Location
    Israel
    Posts
    1,381

    is there sort command n vbscript?

    is there sort command n vbscript?

  2. #2
    Join Date
    Jan 2003
    Location
    Israel
    Posts
    1,381

    can u please post here the bubble sort?

    can i call a javascript function to do it?
    beacuse js has sort!

  3. #3
    Join Date
    Jan 2003
    Location
    Israel
    Posts
    1,381

    ok i fond an answer but .....

    i found example at :
    http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=83

    but when i try this :
    <%@ Language=VBScript %>
    <HTML>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    </HEAD>
    <BODY>

    <P>&nbsp;</P>
    <%
    dim arr
    str="9,5,1,-3"
    arrInput=split(str,",")
    SortArray = Split(SortVBArray(arrInput), Chr(8))
    Response.Write arr(2)
    %>
    <script language="JScript" runat="server">
    function SortVBArray(arrVBArray) {
    return arrVBArray.toArray().sort().join('\b');
    _}
    </Script>
    </BODY>
    </HTML>

    it isnt working!!!
    why?helpp???
    (the error i get is online 19 -invalid character!)

  4. #4
    Join Date
    Jul 2003
    Location
    Strasbourg, France
    Posts
    173
    i ended up making this function:
    Code:
    Function SortArray(aUnsorted, iAsc)
    'variables
    Dim itemp, i, j
    
    'bubble sort (dubble for loop)
    For i = 0 To Ubound(aUnsorted) -1
      For j = i to Ubound(aUnsorted)
    
    If iAsc = 1 Then 'ascending
    
        'exchange items
        If aUnsorted(j) < aUnsorted(i) Then
    	itemp = aUnsorted(i)
            aUnsorted(i) = aUnsorted(j)
    	aUnsorted(j) = itemp
        End if
    Else 'descending
        'exchange items
        If aUnsorted(j) > aUnsorted(i) Then
    	itemp = aUnsorted(i)
            aUnsorted(i) = aUnsorted(j)
    	aUnsorted(j) = itemp
        End if
    end if
    Next
    next
    
    'return value is the sorted array
    SortArray = aUnsorted
    End Function
    Process steps:
    1. you generate an array with the values to be sorted
    2. you call this function
    Code:
    aSortedArray = SortArray(aUnsortedArray, 1) 'if ascending
    aSortedArray = SortArray(aUnsortedArray, 2) 'if descending
    3. You work with the aSortedArray

  5. #5
    Join Date
    Jan 2003
    Location
    Israel
    Posts
    1,381

    ok fixed it

    there was a char not in place
    use the code i put and not buuble sor beacuse i's fater then buuble sort in about 50 times!!!!!!111

  6. #6
    Join Date
    Jan 2003
    Location
    Israel
    Posts
    1,381

    basiclly u correct dave

    but u never can be sure that somewhere in the midle the array will be all sorted out
    which mean's your basic assumption always should be u go all the way....
    which means your run over the array pow(n,2) times!
    peleg

  7. #7
    Join Date
    Jan 2003
    Location
    Israel
    Posts
    1,381

    yes saw

    it's one of the basic thing u learn in algorithems at the university

  8. #8
    Join Date
    Jan 2003
    Location
    Israel
    Posts
    1,381

    Good mornning dave

    i didnt disagree about the flag=1!
    i agree that it improves!
    of course if the array is already sorted or half sorted it will take half the time!
    and if it sorted from the begining
    that it will take O(1) time!
    but when u access the general case u assume that there is a full sort which means u will need O(power(n,2)) in the worset case
    and O(1) in the best case using your flag

    by the way :
    do u have more research pages tha u have done?
    peleg

  9. #9
    Join Date
    Jan 2003
    Location
    Israel
    Posts
    1,381

    thats execlly what i sid

    about the first 1 :
    dont foget that
    O(Power(n,2)) = O(Power(n-1,2))

    Peleg

  10. #10
    Join Date
    Jan 2003
    Location
    Israel
    Posts
    1,381

    ok but what i meant was

    was for general algorithems where
    n= infinity

  11. #11
    Join Date
    Jan 2003
    Location
    Israel
    Posts
    1,381

    how can it be??

    dont u agree with me that
    infinity+1=infinity ???
    or u just jke at me?

  12. #12
    Join Date
    Jan 2003
    Location
    Israel
    Posts
    1,381

    yes there is

    and i will find the algorithem book tha proves it
    and that assumes that
    n-1=infinity=n

  13. #13
    Join Date
    Jan 2003
    Location
    Israel
    Posts
    1,381

    2 question

    fist whee do u put the flag=1 to improve the function?
    second why do u do :
    SortArray = aUnsorted
    when u call the function with the array u want to sort
    the cahnge is being done on the aray itself!
    (beacuse all array's in all lanugages usually passed byRef and not byVal!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles