Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
Today also helped a netizen, my slogan is "to help others for happiness!"
Question: How to achieve the use of ASP to remove three highest points and three minimum points?
1, sorting the entire array, delete both ends of the three maximum and three minimum values (another user proposed!) ）
2, pick out three of the largest number and three minimum number, delete it! (My train of thought!) ）
I think my method should be feasible, because the number of deleted is only three maximum, three minimum, there is no need to all the numbers are sorted, especially when the data are many, will waste a lot of resources! I wrote the following preface:
<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
Call Deletemax (UBound (ARR), 3) ' Removes the three maximum number!
Call Getback () ' Each number is called-1, the smallest number into the maximum number!
Call Deletemax (UBound (ARR), 3) ' Deletes the three maximum number after 1!
Call Getback () ' Restore each number
For kk= 0 to UBound (ARR) ' Output per number
Response.Write (ARR (KK))
Sub Deletemax (Arr_total,willdelete)
For m= 1 to Willdelete
For i= 0 to Arr_total-m
If ARR (i) >arr (i+1) Then
Call Swap (ARR (i), ARR (i+1))
ReDim Preserve ARR (arr_total-m)
Sub Swap (Num_a,num_b) ' Swap two numbers
Sub Getback ()
For L=0 to UBound (ARR)
ARR (L) =arr (L) *-1
%> There are three subroutines:
1, Deletemax (arr_total,willdelete)
Function: Deletes a number of maximum numbers, Arr_total: The maximum available subscript for the array, Willdelete: The number of maximum numbers that will be deleted.
2. Swap (Num_a,num_b)
Function: Swap two numbers
3, Getback ()
function: Multiply each element of the array by 1, and the smallest number to the maximum number!
Help people experience:
Experiment with how to delete an array element!
Cleverly apply ReDim and preserve statements, such as:
Dim A ()
ReDim A (10)
' Want to delete the sixth element a (5)
For n= 5 to UBound (A)-1
A (n) =a (n+1)
ReDim Preserve A (UBound (a)-1) above the code, can be completed, do not believe you try ...
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to email@example.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
and provide relevant evidence. A staff member will contact you within 5 working days.