Skip to content

Instantly share code, notes, and snippets.

@ojulianos
Created March 6, 2023 00:32
Show Gist options
  • Save ojulianos/055784d3db188c77d62efbc16a6c7f8c to your computer and use it in GitHub Desktop.
Save ojulianos/055784d3db188c77d62efbc16a6c7f8c to your computer and use it in GitHub Desktop.
VetorNaoOrdenadoSimples.py
class VetorNaoOrdenado:
def __init__(self, capacidade):
self.__capacidade = capacidade
self.__ultimaPosicao = -1
self.__valores = [0]*self.__capacidade
def imprimir(self):
if self.__ultimaPosicao == -1:
print("Vetor vazio")
else:
for i in range(self.__ultimaPosicao + 1):
print(i, "=", self.__valores[i])
def inserir(self, valor):
if (self.__ultimaPosicao == self.__capacidade-1):
print("Vetor cheio")
else:
self.__ultimaPosicao += 1
self.__valores[self.__ultimaPosicao] = valor
def pesquisar(self, valor):
for i in range(self.__ultimaPosicao + 1):
if valor == self.__valores[i]:
return i
return -1
def excluir(self, valor):
posicao = self.pesquisar(valor)
if posicao == -1:
return -1
else:
for i in range(posicao, self.__ultimaPosicao):
self.__valores[i] = self.__valores[i+1]
self.__ultimaPosicao -= 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment