Allen Software

Posts Tagged ‘training’

Pascal Arrays

Thursday, November 12th, 2015

When searching for maximum and minimum in the cycle is compared elements with an element that claims to be the maximum (minimum). But that's no problem if, for example, sought a minimum, that before sravnimat elements with a variable which will link kept minimal, that it give? May be zero, not as an array can only be a positive number, then the minimum term will be equal to zero, which can not even included in this array. That is needed is a number that will more or all elements of the array, or it will be one element of the array. I'm finding minimum sets this variable to the first element array, ie, min: = a 1, and the cycle starts from the second element, ie the value of the minimum should not be compared with the first element, since it is he is in a variable minimum. Advantages of this appropriation, it is 1) the cycle is reduced by 1.

2) the problem is reduced to a single operation assignment, that is very often seen that as a minimum before the cycle is assigned maxint, ie the maximum number of integers, but here's why, I would agree if all the elements in the array were equal to this number, then yeah okay, but in either case, once at the beginning of the cycle, will go a comparison with the first element of the array, and if he is not equal to a variable minimum, you will need to assign a value the first, and if you still need to assign the codes, and so on, that is, in my opinion is not very convenient to do so. Similarly, when searching a minimum, that is assigned to a variable as the maximum element of the first element array. And like a trifle, but still, you will not have to wrestle with how to assign the same element as miksimalnogo or as a minimum, simply use the first element of delet But what if you want to find the maximum among the negative, or minimal among positive. That is, we can not say with certainty that the first element fits these constraints. I'm doing in this case a cycle in which I find the first appropriate criteria for the item and its assigns responsible for the minimum (maximum) element, and then have him compare the remaining elements of either a one-dimensional array. Remember, even though the computer and do not iron need to overload it unnecessary computations.