inicio mail me! sindicaci;ón

How to realize take out with ASP 3 highest cent and 3 lowest cent

Problem: How does 胊 Sp realize take out 3 highest cent and 3 lowest cent?

Solve train of thought:

1, sort of will whole array, 3 maximum that delete two end and 3 the least values (another netizen puts forward! )

2, choose piece among them 3 the largest number and 3 the smallest number, delete its! (my train of thought! )

I feel my method should be a few more feasible, because want the number that delete to have 3 only the biggest, 3 the smallest, not was necessary to have all number sort, become especially data is very much when, will waste a lot of resource! The order that I write is as follows:

It is quotative content below:

<%@LANGUAGE= "VBSCRIPT" CODEPAGE= "936" %>
<% Dim Arr
Arr=array(91, 39, 46, 24, 14, 56, 31, 32, 56, 89)

Call DeleteMax(UBound(Arr) , 3)’ deletes 3 the largest number! Every number says Call GetBack()’ with - 1, the will smallest number becomes the largest number! Call DeleteMax(UBound(Arr) , 3)’ is deleted say with - 1 later 3 the largest number! Call GetBack()’ is reductive each numberFor Kk= 0 To UBound(Arr)’ exports each number
Response.Write(Arr(kk) )
Response.Write("<br>" )NextSub DeleteMax(Arr_total, willdelete)For M= 1 To WilldeleteFor I= 0 To Arr_total-mIf Arr(i)>Arr(i 1) Then Call Swap(Arr(i) , arr(i 1) )End IfNext
ReDim Preserve Arr(Arr_total-m) NextEnd SubSub Swap(num_a, num_b)’ exchanges two numberX=num_aNum_a=num_bNum_b=xEnd SubSub GetBack()For L=0 To UBound(Arr)
Arr(L)=Arr(L)*-1NextEnd Sub
%>

Have 3 subprograms among them:

1, DeleteMax(Arr_total, willdelete)

Function: Delete a certain number of several the biggest, arr_total: The biggest usable suffix of array, willdelete: A number of the largest number that will delete.

2, Swap(num_a, num_b)

Function: Exchange two number

3, GetBack()

Function: Take every element of array with - 1, the will smallest number becomes the largest number!

Result:

The trial went how to delete an array element!

Clever application Redim and Preserve statement, be like:

It is quotative content below:

Dim A()Redim A(10)
’ wants to delete A(5 of the 6th element)For N= 5 To Ubound(A)-1
A(n)=A(n 1)NextRedim Preserve A(ubound(A)-1)

The code of above, can finish, do not believe you to try. . .

Bookmark:Digg Del.icio.us Reddit

Leave a Comment