Skip to content

Instantly share code, notes, and snippets.

Created March 6, 2023 00:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
class VetorNaoOrdenado:
def __init__(self, capacidade):
self.__capacidade = capacidade
self.__ultimaPosicao = -1
self.__valores = [0]*self.__capacidade
def imprimir(self):
if self.__ultimaPosicao == -1:
return print("Vetor vazio")
for i in range(self.__ultimaPosicao + 1):
print(i, "=", self.__valores[i])
def inserir(self, valor):
if (self.__ultimaPosicao == self.__capacidade-1):
return print("Vetor cheio")
posicao = self.pesquisar(valor)
if(posicao != -1):
return print('Valor já existe no vetor')
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
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