Sort disjoint sublist: Difference between revisions

Grouping BASIC dialects
(Added various BASIC dialects)
(Grouping BASIC dialects)
Line 1,065:
==={{header|Applesoft BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> INSTALL @lib$+"SORTLIB"
Sort% = FN_sortinit(0,0) : REM Ascending
DIM list%(7) : list%() = 7, 6, 5, 4, 3, 2, 1, 0
DIM indices%(2) : indices%() = 6, 1, 7
PROCsortdisjoint(list%(), indices%())
PRINT FNshowlist(list%())
END
DEF PROCsortdisjoint(l%(), i%())
LOCAL C%, i%, n%, t%()
n% = DIM(i%(),1)
DIM t%(n%)
FOR i% = 0 TO n%
t%(i%) = l%(i%(i%))
NEXT
C% = n% + 1
CALL Sort%, i%(0)
CALL Sort%, t%(0)
FOR i% = 0 TO n%
l%(i%(i%)) = t%(i%)
NEXT
ENDPROC
DEF FNshowlist(l%())
LOCAL i%, o$
o$ = "["
FOR i% = 0 TO DIM(l%(),1)
o$ += STR$(l%(i%)) + ", "
NEXT
= LEFT$(LEFT$(o$)) + "]"</syntaxhighlight>
{{out}}
<pre>[7, 0, 5, 4, 3, 2, 1, 6]</pre>
 
==={{header|Chipmunk Basic}}===
Line 1,099 ⟶ 1,136:
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">dim as integer value(0 to 7) = {7, 6, 5, 4, 3, 2, 1, 0}
dim as integer index(0 to 2) = {6, 1, 7}, i
 
for i = 0 to 1
if value(index(i))>value(index(i+1)) then
swap value(index(i)), value(index(i+1))
end if
next i
 
for i = 0 to 7
print value(i);
next i : print</syntaxhighlight>
{{out}}<pre> 7 0 5 4 3 2 1 6</pre>
 
==={{header|GW-BASIC}}===
Line 1,176 ⟶ 1,228:
{{works with|MSX BASIC|any}}
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|Run BASIC}}===
Normally we sort with SQLite in memory. Faster and less code
<syntaxhighlight lang="runbasic">sortData$ = "7, 6, 5, 4, 3, 2, 1, 0"
sortIdx$ = "7, 2, 8"
 
numSort = 8
dim sortData(numSort)
for i = 1 to numSort
sortData(i) = val(word$(sortData$,i,","))
next i
 
while word$(sortIdx$,s + 1) <> ""
s = s + 1
idx = val(word$(sortIdx$,s))
gosub [bubbleSort]
wend
end
 
[bubbleSort]
sortSw = 1
while sortSw = 1
sortSw = 0
for i = idx to numSort - 1 ' start sorting at idx
if sortData(i) > sortData(i+1) then
sortSw = 1
sortHold = sortData(i)
sortData(i) = sortData(i+1)
sortData(i+1) = sortHold
end if
next i
wend
RETURN</syntaxhighlight>
 
==={{header|True BASIC}}===
Line 1,213 ⟶ 1,298:
{{out}}
<pre>Same as BASIC entry.</pre>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> INSTALL @lib$+"SORTLIB"
Sort% = FN_sortinit(0,0) : REM Ascending
DIM list%(7) : list%() = 7, 6, 5, 4, 3, 2, 1, 0
DIM indices%(2) : indices%() = 6, 1, 7
PROCsortdisjoint(list%(), indices%())
PRINT FNshowlist(list%())
END
DEF PROCsortdisjoint(l%(), i%())
LOCAL C%, i%, n%, t%()
n% = DIM(i%(),1)
DIM t%(n%)
FOR i% = 0 TO n%
t%(i%) = l%(i%(i%))
NEXT
C% = n% + 1
CALL Sort%, i%(0)
CALL Sort%, t%(0)
FOR i% = 0 TO n%
l%(i%(i%)) = t%(i%)
NEXT
ENDPROC
DEF FNshowlist(l%())
LOCAL i%, o$
o$ = "["
FOR i% = 0 TO DIM(l%(),1)
o$ += STR$(l%(i%)) + ", "
NEXT
= LEFT$(LEFT$(o$)) + "]"</syntaxhighlight>
'''Output:'''
<pre>
[7, 0, 5, 4, 3, 2, 1, 6]
</pre>
 
=={{header|Bracmat}}==
Line 1,270 ⟶ 1,316:
)
& out$!values;</syntaxhighlight>
{{out}}
Output:
<pre>7 0 5 4 3 2 1 6</pre>
 
Line 1,880 ⟶ 1,926:
end subroutine Isort
end program Example</syntaxhighlight>
{{out}}
Output
<pre> 7 0 5 4 3 2 1 6</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">dim as integer value(0 to 7) = {7, 6, 5, 4, 3, 2, 1, 0}
dim as integer index(0 to 2) = {6, 1, 7}, i
 
for i = 0 to 1
if value(index(i))>value(index(i+1)) then
swap value(index(i)), value(index(i+1))
end if
next i
 
for i = 0 to 7
print value(i);
next i : print</syntaxhighlight>
{{out}}<pre> 7 0 5 4 3 2 1 6</pre>
 
=={{header|Go}}==
Line 3,463 ⟶ 3,494:
indices = [6, 1, 7]
p sort_disjoint_sublist!(values, indices)</syntaxhighlight>
{{out}}
Output
<pre>[7, 0, 5, 4, 3, 2, 1, 6]</pre>
 
=={{header|Run BASIC}}==
Normally we sort with SQLite in memory. Faster and less code
<syntaxhighlight lang="runbasic">sortData$ = "7, 6, 5, 4, 3, 2, 1, 0"
sortIdx$ = "7, 2, 8"
 
numSort = 8
dim sortData(numSort)
for i = 1 to numSort
sortData(i) = val(word$(sortData$,i,","))
next i
 
while word$(sortIdx$,s + 1) <> ""
s = s + 1
idx = val(word$(sortIdx$,s))
gosub [bubbleSort]
wend
end
 
[bubbleSort]
sortSw = 1
while sortSw = 1
sortSw = 0
for i = idx to numSort - 1 ' start sorting at idx
if sortData(i) > sortData(i+1) then
sortSw = 1
sortHold = sortData(i)
sortData(i) = sortData(i+1)
sortData(i+1) = sortHold
end if
next i
wend
RETURN</syntaxhighlight>
 
=={{header|Rust}}==
 
 
<syntaxhighlight lang="rust">use std::collections::BTreeSet;
 
Line 3,521 ⟶ 3,517:
disjoint_sort(&mut array, &indices);
println!("{:?}", array);
}</syntaxhighlight>
}
</syntaxhighlight>
 
{{out}}
 
<pre>[7, 0, 5, 4, 3, 2, 1, 6]</pre>
 
Line 3,566 ⟶ 3,559:
car))</syntaxhighlight>
{{output}}
<pre>(7 0 5 4 3 2 1 6)</pre>
<pre>
(7 0 5 4 3 2 1 6)
</pre>
 
=={{header|Sidef}}==
Line 3,703 ⟶ 3,694:
set indices {6 1 7}
puts \[[join [disjointSort $values $indices] ", "]\]</syntaxhighlight>
{{out}}
Output:
<pre>[7, 0, 5, 4, 3, 2, 1, 6]</pre>
 
=={{header|TUSCRIPT}}==
TUSCRIPT indexing is one based
<syntaxhighlight lang="tuscript">$$ MODE TUSCRIPT
$$ MODE TUSCRIPT
values="7'6'5'4'3'2'1'0"
indices="7'2'8"
Line 3,718 ⟶ 3,708:
values=REPLACE (values,#i,v)
ENDLOOP
PRINT values</syntaxhighlight>
{{out}}
</syntaxhighlight>
<pre>7'0'5'4'3'2'1'6 </pre>
Output:
<pre>
7'0'5'4'3'2'1'6
</pre>
 
=={{header|Ursala}}==
Line 3,734 ⟶ 3,721:
 
t = disjoint_sort({6,1,7},<7,6,5,4,3,2,1,0>)</syntaxhighlight>
{{out}}
output:
<pre><7,0,5,4,3,2,1,6></pre>
 
Line 3,759 ⟶ 3,746:
sortDisjoint.call(values, indices)
System.print("Sorted : %(values)")</syntaxhighlight>
 
{{out}}
<pre>Initial: [7, 6, 5, 4, 3, 2, 1, 0]
<pre>
InitialSorted : [7, 60, 5, 4, 3, 2, 1, 06]</pre>
Sorted : [7, 0, 5, 4, 3, 2, 1, 6]
</pre>
 
=={{header|XPL0}}==
Line 3,782 ⟶ 3,766:
[IntOut(0, Values(I)); ChOut(0, ^ )];
]</syntaxhighlight>
 
{{out}}
<pre>7 0 5 4 3 2 1 6 </pre>
<pre>
7 0 5 4 3 2 1 6
</pre>
 
=={{header|zkl}}==
Line 3,804 ⟶ 3,785:
 
values.println(); // modified list</syntaxhighlight>
{{out}}
{{out}}<pre>L(7,0,5,4,3,2,1,6)</pre>
<pre>L(7,0,5,4,3,2,1,6)</pre>
2,130

edits