TPK algorithm: Difference between revisions

Content deleted Content added
C++ implementation: call f() on members of S, not the indices
m -<code>
Line 8:
 
==The algorithm==
<code lang="pseudocode">
'''ask''' for 11 numbers to be read into a sequence ''S''
'''reverse''' sequence ''S''
Line 17 ⟶ 16:
'''else'''
'''print''' ''result''
</code>
 
The algorithm reads eleven numbers from an input device, stores them in an array, and then processes them in reverse order, applying a user-defined function to each value and reporting either the value of the function or a message to the effect that the value has exceeded some threshold.
Line 23 ⟶ 21:
==[[ALGOL 60]] implementation==
<!-- Note that ALGOL is not correctly colored by <source>. -->
<code lang="algol60">
'''begin integer''' i; '''real''' y; '''real array''' a[0:10];
'''real procedure''' f(t); '''real''' t; '''value''' t;
Line 34 ⟶ 31:
'''end'''
'''end'''
</code>
 
The problem with the usually specified function is that the term <code>5*t^3</code> gives overflows in almost all languages for very large negative values.