Naming Conventions |
|||||
|
Scalar |
Vector |
Matrix |
Any |
Non- |
Boolean |
BS |
BV |
BM |
BA |
BN |
Integer |
IS |
IV |
IM |
IA |
IN |
Float |
FS |
FV |
FM |
FA |
FN |
Numeric |
NS |
NV |
NM |
NA |
NN |
Character |
CS |
CV |
CM |
CA |
CN |
Enclosed |
ES |
EV |
EM |
EA |
EN |
enclosed |
TS |
TV |
TM |
TA |
TN |
Simple |
SS |
SV |
SM |
SA |
SN |
Any |
AS |
AV |
AM |
AA |
AN |
phrase e.g.: .X...Y. ⍝ X←BS; Y←IV |
|||||
combinations: use ISV for Integer scalar∨vector |
|||||
B3, I4 &c. to specify higher ranks. |
|||||
CheckAscendingOrder
This phrase can be used to check whether the items in a numeric vector are in ascending order
</NV≥1⌽NV
The phrase may also be written in the following form, but it executes slower in some APL implementations:
NV<.≥1⌽NV
Note that the test determines whether the items are in strictly ascending order - i.e. each item is larger than the last. If the vector contains duplicates it is not considered to be in ascending order.
To test whether a vector containing duplicates is in ascending order, you can use any of the following phrases. Performance characteristics vary depending on the length of NV and the APL interpreter used:
</NV>1⌽NV
NV<.>1⌽NV
NV≡NV[⍋NV]
(⍋NV)≡⍳⍴NVIn all cases, you should the check the result of the phrase when NV is an empty vector if this is important to your application.
Examples
⎕FX ⍕2 1⍴'r←CheckAscendingOrder NV' 'r←</NV≥1⌽NV'
CheckAscendingOrder 0 1 5 8 19 27
1
CheckAscendingOrder ¯3.1 ¯3.0 1.5 5.3 17
1
CheckAscendingOrder 1 3 2 5 7 8
0
CheckAscendingOrder 1 2 3 5 7 8
1
CheckAscendingOrder 1 1 2 5 7 8 ⍝ Contains duplicates
0
Compatibility
Checked with: APLX, APL+Win
Test Cases
Show test cases
Test my code, both Examples and Test Cases.
See also: ...
Mentor: SimonMarsden
Tags: <!Ascending> <Ordering> <Sorting>
APL Wiki