# 1 - Greg Thorson CS10051 Section 005 Austin C Melton March...

This preview shows pages 1–2. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Greg Thorson CS10051 Section 005 Austin C. Melton March 24th, 2008 1. The algorithm finds the largest so far and then compares that value to each value it comes across in the duration of the algorithm. Then if the largest value occurs in the list multiple times, then the algorithm prints out the location of the first occurrence so that the algorithm only notices the first one and does not repeat for the same value. 2. Get a value for n, the size of the list Get values for A1...A2...An, the list to be searched Set largest so far to Ai Set the value of location to 1 Set the value of i to 2 While (i< or = n) do If Ai is > or = to the largest so far then Set largest so far to Ai Set location to i Print the value of largest so far and location Add 1 to i Endwhile 3. Get a value for n, the size of the list Get values for A1...A2...An, the list to be searched Set largest so far to A1 Set the value of location to 1 Set the value of i to 2 Set the value of c to 0 While (i< or = n) do If Ai > the largest so far then Set largest so far to Ai Set location to i Set c to 0 End If If Ai = the largest so far then If c < 4 Set location to i Add 1 to c End if End If Add 1 to i Endwhile Print the value of largest so far and location Stop 4. Get a value for n, the size of the list Get values for A1...A2...An, the list to be searched Set least so far to Ai Set the value of location to 1 Set the value of i to 2 While (i< or = n) do If Ai is < or = to the least so far then Set least so far to Ai Set location to i Add 1 to i Endwhile Print the value of least so far and location Stop ...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

1 - Greg Thorson CS10051 Section 005 Austin C Melton March...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online