Created
February 16, 2018 02:26
-
-
Save danielnunesdc/ade08fe712b5de99352a0b2ef82733b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from time import time | |
| from random import shuffle | |
| def busca_sequencial_sentinela(v, x): | |
| i = 0 | |
| v.append(x) | |
| while v[i] != x: | |
| i += 1 | |
| if i == len(v) - 1: | |
| return -1 | |
| return i | |
| vetor = list(range(0, 101)) | |
| shuffle(vetor) | |
| print(vetor) | |
| chave = 40 | |
| antes = time() | |
| posicao = busca_sequencial_sentinela(vetor, chave) | |
| depois = time() | |
| total = (depois - antes) * 1000 | |
| if posicao >= 0: | |
| print('\nO elemento {} foi encontrado na posição {}.'.format(chave, posicao)) | |
| else: | |
| print('\no elemento NÃO foi encontrado.') | |
| print('\nO tempo total gasto foi {:.2} ms.'.format(total)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment