Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
web2solutions committed Aug 4, 2023
2 parents a0809b4 + 4b85727 commit 3054863
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
4 changes: 3 additions & 1 deletion docs/Pilhas.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Caso a pilha esteja `cheia` e haja a tentativa de um `empilhamento` deve ocorrer

`primeiro objeto a ser inserido na pilha é o último a ser removido`.

Com isso fica aberta a possibilidade de usar o início do vetor como topo e o final como base da pilha. Darei o nome á essa implementação de `Pilha inversa`.
Com isso fica aberta a possibilidade de usar o início do vetor como topo e o final como base da pilha. Darei o nome á essa implementação de `Pilha inversa` e que possui tempo de `O(n)` no pior cenário, pois ao remover o primeiro item do vetor, o mesmo é completamente redimensionado.

topo = Pilha[0]
base = Pilha[Pilha.length - 1]
Expand Down Expand Up @@ -173,6 +173,7 @@ export class Pilha <T> {
if (this.tamanho === this.capacidade) {
throw new Error('Pilha transbordada - Stack overflow')
}
// O(1)
this.pilha.push(valor);
return this.pilha;
}
Expand All @@ -182,6 +183,7 @@ export class Pilha <T> {
if (!(this.pilha.length > 0)) {
throw new Error('Pilha vazia');
}
// O(1)
return this.pilha.pop() as unknown as T;
}

Expand Down
16 changes: 6 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3054863

Please sign in to comment.