How to resolve the algorithm Sort numbers lexicographically step by step in the Ksh programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sort numbers lexicographically step by step in the Ksh 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 Ksh programming language
Source code in the ksh programming language
#!/bin/ksh
# Sort numbers lexicographically
# # Variables:
#
integer N=${1:-13}
# # Functions:
#
# # Function _fillarray(arr, N) - fill assoc. array 1 -> N
#
function _fillarray {
typeset _arr ; nameref _arr="$1"
typeset _N ; integer _N=$2
typeset _i _st _en ; integer _i _st _en
(( ! _N )) && _arr=0 && return
(( _N<0 )) && _st=${_N} && _en=1
(( _N>0 )) && _st=1 && _en=${_N}
for ((_i=_st; _i<=_en; _i++)); do
_arr[${_i}]=${_i}
done
}
######
# main #
######
set -a -s -A arr
typeset -A arr
_fillarray arr ${N}
print -- ${arr[*]}
You may also check:How to resolve the algorithm Determine if a string has all the same characters step by step in the BASIC programming language
You may also check:How to resolve the algorithm 100 prisoners step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Comments step by step in the C# programming language
You may also check:How to resolve the algorithm Non-decimal radices/Output step by step in the Wren programming language
You may also check:How to resolve the algorithm Empty string step by step in the Go programming language