Jump to content

Decorate-sort-undecorate idiom: Difference between revisions

Added QBasic
(Added QBasic)
Line 155:
=={{header|FreeBASIC}}==
FreeBASIC doesn't normally print string lists in "quoted" form though I've added the quotes here to be consistent with the other solutions.
<syntaxhighlight lang="vb">Type' mapRosetta Code problem: https://rosettacode.org/wiki/Decorate-sort-undecorate_idiom
' by Jjuanhdez, 07/2023
 
Type map
x As String
y As Integer
Line 333 ⟶ 336:
{{out}}
<pre>['Rosetta', 'Code', 'is', 'a', 'programming', 'chrestomathy', 'site'] => ['a', 'is', 'Code', 'site', 'Rosetta', 'programming', 'chrestomathy']</pre>
 
=={{header|QBasic}}==
{{trans|FreeBASIC}}
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">TYPE map
x AS STRING * 12
y AS INTEGER
END TYPE
 
SUB Schwartzian (a$())
DIM e(0 TO 6, 0 TO 6) AS map
' Decorate
FOR p = 0 TO 6
e(p, 1).x = a$(p)
e(1, p).y = LEN(a$(p))
NEXT p
' Sort
CALL Sort(e())
' Undecorate
FOR p = 0 TO 6
PRINT e(p, 1).x
NEXT p
END SUB
 
SUB Sort (array() AS map)
FOR i = 0 TO 6 - 1
min = i
FOR j = i + 1 TO 6
IF array(1, j).y <= array(1, min).y THEN min = j
NEXT j
SWAP array(min, 1).x, array(i, 1).x
SWAP array(1, min).y, array(1, i).y
NEXT i
END SUB
 
DIM words(6) AS STRING
DATA "Rosetta", "Code", "is", "a", "programming", "chrestomathy", "site"
FOR i = 0 TO 6
READ words(i)
NEXT i
CALL Schwartzian(words())
END</syntaxhighlight>
{{out}}
<pre>a
is
site
Code
Rosetta
programming
chrestomathy</pre>
 
=={{header|Raku}}==
2,169

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.