Naming Conventions

Scalar

Vector

Matrix

Any
rank

Non-
scalar

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
vector

ES

EV

EM

EA

EN

enclosed
Text vector

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 scalarvector

B3, I4 &c. to specify higher ranks.

Open full technical reference

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)≡⍳⍴NV

In 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
 ⎕IO←0      ⍝ You may change this; however, zero IS the default in the Phrasebook
⍝⎕ML←3      ⍝ Enable this line in Dyalog APL if appropriate
 ⎕FX'r←CheckAscendingOrder NV' 'r←</NV≥1⌽NV'
⍝ ---- Start Test cases (do not delete this!)
NV←77.3 153.5 23.6 152.3 ¯19.3 24.5 61.1 40.1 ¯13.9 ¯46.6
0 ≡ CheckAscendingOrder NV
NV←NV[⍋NV]
1 ≡ CheckAscendingOrder NV
0 ≡ CheckAscendingOrder 1 1 1 2 2 2

For details see the PhraseBook/TestCasesGuidelines.

Test my code, both Examples and Test Cases.

See also: ...

Mentor: SimonMarsden

Tags: <!Ascending> <Ordering> <Sorting>


CategoryPhrasesAll

PhraseBook/CheckAscendingOrder (last edited 2011-12-26 10:45:44 by KaiJaeger)