Click to See Complete Forum and Search --> : is there sort command n vbscript?


pelegk1
08-12-2003, 07:07 AM
is there sort command n vbscript?

pelegk1
08-12-2003, 10:01 AM
can i call a javascript function to do it?
beacuse js has sort!

pelegk1
08-12-2003, 10:19 AM
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!)

rdoekes
08-12-2003, 10:54 AM
i ended up making this function:

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 aSortedArray = SortArray(aUnsortedArray, 1) 'if ascending
aSortedArray = SortArray(aUnsortedArray, 2) 'if descending
3. You work with the aSortedArray

pelegk1
08-13-2003, 01:46 AM
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

pelegk1
08-13-2003, 09:25 AM
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

pelegk1
08-17-2003, 03:16 AM
it's one of the basic thing u learn in algorithems at the university

pelegk1
08-18-2003, 01:46 AM
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

pelegk1
08-18-2003, 09:21 AM
about the first 1 :
dont foget that
O(Power(n,2)) = O(Power(n-1,2))

Peleg

pelegk1
08-18-2003, 09:31 AM
was for general algorithems where
n= infinity :):cool: :D :( ;) :p :o :mad: :eek:

pelegk1
08-18-2003, 09:58 AM
dont u agree with me that
infinity+1=infinity ???
or u just jke at me?

pelegk1
08-19-2003, 02:11 AM
and i will find the algorithem book tha proves it
and that assumes that
n-1=infinity=n

pelegk1
09-11-2003, 04:36 AM
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!