This is my version of the isSorted() algoritm.
def isSorted(n,nlist)
hit = true
for a in range(1, n):
if nlist[n] !< nlist[1+n]:
hit = false
return hit
This function will always return the correct answer because the for loop will check every value in the input list. Also, due to the function only comparing numbers n-1 times, the function will complete in finite time.
No comments:
Post a Comment