Last list item: Difference between revisions
→{{header|Ring}}
Line 490:
=={{header|Ring}}==
===
<lang ring>
see "working..." + nl
List = [6,81,243,14,25,49,123,69,11]
n = 0
while true
n++
first =
second =
see nl▼
ok▼
first = min(List)▼
ind1 = find(List,first)
del(List,ind1)▼
second = min(List)▼
ind2 = find(List,second)
del(List,ind2)▼
del(List,ind1)▼
else▼
del(List,ind1)▼
del(List,ind2)▼
▲ ok
sum = first + second
add(List,sum)
if len(List) = 1
exit
ok▼
if n = 1▼
see nl + "List = "▼
showArray(List)▼
▲ see nl
ok
showList(first,second,sum,List)
end
see "Last item is: " +List[1] + nl
see "done..." + nl
func showList(first,second,sum,List)
see "two smallest is = " + first + " + " + second + " = " + sum + nl
see "List = "
showArray(List)
func showArray(array)
txt = ""
Line 540 ⟶ 546:
working...
List = [
two smallest is = 6 + 11 = 17
List = [
two smallest is = 14 + 17 = 31
List = [
two smallest is = 25 + 31 = 56
List = [
two smallest is = 49 + 56 = 105
List = [69,81
two smallest is = 69 + 81 = 150
List = [
two smallest is = 105 + 123 = 228
List = [
two smallest is = 150 + 228 = 378
List = [243,378]
Line 559 ⟶ 565:
done...
</pre>
===
<lang ring>
see "working..." + nl
List = [6,81,243,14,25,49,123,69,11]
n = 0
while true
n++
see nl▼
ok▼
▲ first = min(List)
ind1 = find(List,first)
▲ del(List,ind1)
▲ second = min(List)
ind2 = find(List,second)
▲ del(List,ind2)
▲ del(List,ind1)
▲ else
▲ del(List,ind1)
▲ del(List,ind2)
▲ ok
sum = first + second
add(List,sum)
if len(List) = 1
exit
▲ ok
▲ if n = 1
▲ see nl + "List = "
▲ showArray(List)
▲ see nl
ok
showList(first,second,sum,List)
end
see "Last item is: " +List[1] + nl
see "done..." + nl
func showList(first,second,sum,List)
see "two smallest is = " + first + " + " + second + " = " + sum + nl
see "List = "
showArray(List)
func showArray(array)
txt = ""
Line 615:
working...
List = [6,81,243,14,25,49
two smallest is = 6 + 11 = 17
List = [81,243,14,25,49
two smallest is = 14 + 17 = 31
List = [81,243,25,49
two smallest is = 25 + 31 = 56
List = [
two smallest is = 49 + 56 = 105
List = [
two smallest is = 69 + 81 = 150
List = [
two smallest is = 105 + 123 = 228
List = [
two smallest is = 150 + 228 = 378
List = [243,378]
|