Created
February 16, 2018 02:25
-
-
Save danielnunesdc/22cd79819ed55f9e2a06cae9bb2d51a3 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(v, x): | |
| indice = 0 | |
| while indice < len(v): | |
| if v[indice] == x: | |
| return indice | |
| indice += 1 | |
| return -1 | |
| vetor = list(range(0, 100)) | |
| shuffle(vetor) | |
| print(vetor) | |
| chave = 40 | |
| antes = time() | |
| posicao = busca_sequencial(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