How to resolve the algorithm Sort numbers lexicographically step by step in the Action! programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sort numbers lexicographically step by step in the Action! programming language
Table of Contents
Problem Statement
Given an integer n, return 1──►n (inclusive) in lexicographical order.
Show all output here on this page.
Given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9].
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sort numbers lexicographically step by step in the Action! programming language
Source code in the action! programming language
PROC PrintArray(INT ARRAY a INT size)
INT i
Put('[)
FOR i=0 TO size-1
DO
IF i>0 THEN Put(' ) FI
PrintI(a(i))
OD
Put(']) PutE()
RETURN
INT FUNC Compare(INT a1,a2)
CHAR ARRAY s1(10),s2(10)
INT res
StrI(a1,s1) StrI(a2,s2)
res=SCompare(s1,s2)
RETURN (res)
PROC InsertionSort(INT ARRAY a INT size)
INT i,j,value
FOR i=1 TO size-1
DO
value=a(i)
j=i-1
WHILE j>=0 AND Compare(a(j),value)>0
DO
a(j+1)=a(j)
j==-1
OD
a(j+1)=value
OD
RETURN
PROC Test(INT ARRAY a INT size)
PrintE("Array before sort:")
PrintArray(a,size)
InsertionSort(a,size)
PrintE("Array after sort:")
PrintArray(a,size)
PutE()
RETURN
PROC Main()
DEFINE COUNT_A="13"
DEFINE COUNT_B="50"
INT ARRAY a(COUNT_A),b(COUNT_B)
BYTE i
FOR i=1 TO COUNT_A
DO a(i-1)=i OD
FOR i=1 TO COUNT_B
DO b(i-1)=i OD
Test(a,COUNT_A)
Test(b,COUNT_B)
RETURN
You may also check:How to resolve the algorithm Factorial base numbers indexing permutations of a collection step by step in the Quackery programming language
You may also check:How to resolve the algorithm Variable-length quantity step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Create a file step by step in the Yabasic programming language
You may also check:How to resolve the algorithm Mutual recursion step by step in the Oz programming language
You may also check:How to resolve the algorithm Soundex step by step in the TSE SAL programming language