Algorithms

Finding Largest

1. read n, the size of the list

2. read A1, A2, ... , An

3. largest_so_far <- A1

4. location <- 1

5. i <- 2

6. while i <n do

7.    if Ai > largest_so_far then

8.       largest_so_far <- Ai

9.       location <- i

10.      i <- i + 1

11. write largest_so_far, location

12. stop

[Prev][TOC][Next]


CS1104 Main Page
Last Updated 01/05/2000
© L.Heath, 2000