How to resolve the algorithm Sort numbers lexicographically step by step in the FreeBASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sort numbers lexicographically step by step in the FreeBASIC 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 FreeBASIC programming language
Source code in the freebasic programming language
function leq( n as integer, m as integer ) as boolean
if str(n)<=str(m) then return true else return false
end function
sub shellsort(s() as integer)
dim as integer n = ubound(s)
dim as integer i, inc = n
dim as boolean done
do
inc\=2.2
if inc = 0 then inc = 1
do
done = false
for i = 0 to n - inc
if leq(s(i+inc), s(i)) then
swap s(i), s(i + inc)
done = true
end if
next
loop until done = 0
loop until inc = 1
end sub
dim as integer n, i
input n
dim as integer s(0 to n-1)
for i = 0 to n-1
s(i) = i+1
next i
shellsort(s())
print "[";
for i = 0 to n-1
print s(i);
if i
next i
print "]"
You may also check:How to resolve the algorithm Best shuffle step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Dijkstra's algorithm step by step in the Swift programming language
You may also check:How to resolve the algorithm Harshad or Niven series step by step in the Action! programming language
You may also check:How to resolve the algorithm Empty string step by step in the Asymptote programming language
You may also check:How to resolve the algorithm Repeat a string step by step in the Swift programming language