Related questions with answers
We call the algorithm "firstrepeated" and the input is a list of integers
firstrepeated(: integers with )
We will first define a value "location", which we set to 0 and will be set to the position of the repeated number (if there is one). will be the position in the list that we are comparing to the previous positions .
The algorithm should stop when the a location of a repeated number was found (and thus if location is no longer zero). The algorithm should also stop if we checked every element in the list.
We compare every element in position to the elements in previous positions . If the elements are equal, then we set the variable "location" to the location of the repeated number.
Finally we return the value "location" which is the position of the first repeated value.
Recommended textbook solutions
More related questions