How to resolve the algorithm Order two numerical lists step by step in the VBScript programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Order two numerical lists step by step in the VBScript programming language
Table of Contents
Problem Statement
Write a function that orders two lists or arrays filled with numbers. The function should accept two lists as arguments and return true if the first list should be ordered before the second, and false otherwise. The order is determined by lexicographic order: Comparing the first element of each list. If the first elements are equal, then the second elements should be compared, and so on, until one of the list has no more elements. If the first list runs out of elements the result is true. If the second list or both run out of elements the result is false. Note: further clarification of lexicographical ordering is expounded on the talk page here and here.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Order two numerical lists step by step in the VBScript programming language
Source code in the vbscript programming language
Function order_list(arr1,arr2)
order_list = "FAIL"
n1 = UBound(arr1): n2 = UBound(arr2)
n = 0 : p = 0
If n1 > n2 Then
max = n2
Else
max = n1
End If
For i = 0 To max
If arr1(i) > arr2(i) Then
n = n + 1
ElseIf arr1(i) = arr2(i) Then
p = p + 1
End If
Next
If (n1 < n2 And n = 0) Or _
(n1 = n2 And n = 0 And p - 1 <> n1) Or _
(n1 > n2 And n = 0 And p = n2) Then
order_list = "PASS"
End If
End Function
WScript.StdOut.WriteLine order_list(Array(-1),Array(0))
WScript.StdOut.WriteLine order_list(Array(0),Array(0))
WScript.StdOut.WriteLine order_list(Array(0),Array(-1))
WScript.StdOut.WriteLine order_list(Array(0),Array(0,-1))
WScript.StdOut.WriteLine order_list(Array(0),Array(0,0))
WScript.StdOut.WriteLine order_list(Array(0),Array(0,1))
WScript.StdOut.WriteLine order_list(Array(0,-1),Array(0))
WScript.StdOut.WriteLine order_list(Array(0,0),Array(0))
WScript.StdOut.WriteLine order_list(Array(0,0),Array(1))
WScript.StdOut.WriteLine order_list(Array(1,2,1,3,2),Array(1,2,0,4,4,0,0,0))
You may also check:How to resolve the algorithm XML/DOM serialization step by step in the Sidef programming language
You may also check:How to resolve the algorithm Mutual recursion step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Nth root step by step in the 11l programming language
You may also check:How to resolve the algorithm Least common multiple step by step in the Vala programming language
You may also check:How to resolve the algorithm Pascal's triangle step by step in the Tcl programming language