Title: Algorithm 1.2.1 Finding the Maximum of Three Numbers
1CHAPTER 1
2Algorithm 1.2.1 Finding the Maximum of Three
Numbers
This algorithm finds the largest of the numbers
a, b, and c.
Input Parameters a, b, c Output Parameter
x max(a,b,c,x) x a if (b gt x) // if b is
larger than x, update x x b if (c gt x) //
if c is larger than x, update x x c
3Algorithm 1.2.2 Finding the Maximum Value in an
Array Using a While Loop
This algorithm finds the largest number in the
array s1, s2, ... , sn.
Input Parameter s Output Parameters
None array_max_ver1(s) large s1 i 2
while (i s.last) if (si gt large) //
larger value found large si i i
1 return large
4Algorithm 1.2.4 Finding the Maximum Value in an
Array Using a For Loop
This algorithm finds the largest number in the
array s1, s2, ... , sn.
Input Parameter s Output Parameters
None array_max_ver2(s) large s1 for i
2 to s.last if (si gt large) // larger
value found large si return large
5Algorithm 1.3.1 Array Shuffle
This algorithm shuffles the values in the array
a1, a2, ... , an.
Input Parameter a Output Parameters
a shuffle(a) for i 1 to a.last -
1 swap(ai, arand(i,a.last))