Skip to content

Commit

Permalink
Merge pull request #5 from cassiozareck/main
Browse files Browse the repository at this point in the history
Simplificação pop
  • Loading branch information
cassiozareck authored Nov 21, 2023
2 parents a38fb41 + cfb6583 commit fffd6f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions src/ListTools.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,16 @@ void inicializaPilha(struct Pilha **head){
****************************************************************/
int pop(struct Pilha **head){
//se a pilha estiver vazia
if((*head)->topo == NULL){
return -1;
}
struct NodoPilha *aux;
int vertice;
// se a pilha tiver 2 nodos
if((*head)->topo->prox != NULL){
aux = (*head)->topo; // aux aponta para o nodo no topo
(*head)->topo = (*head)->topo->prox; // Diminui topo "pop"
vertice = aux->vertice;
free(aux); // Libera espaço de memoria
return vertice;
// senão a pilha tem somente 1 nodo
}else{
aux = (*head)->topo; // aux aponta para o nodo no topo
(*head)->topo = NULL; // topo aponta para NULL
vertice = aux->vertice;
free(aux); // Libera espaço de memoria
return vertice;
}
if((*head)->topo == NULL) return -1;
struct NodoPilha *aux = (*head)->topo;

int vertice = aux->vertice;

if((*head)->topo->prox != NULL) (*head)->topo = (*head)->topo->prox;
else (*head)->topo = NULL;

free(aux);
return vertice;
}
/*************************************************
* push *
Expand Down
Binary file added src/main
Binary file not shown.

0 comments on commit fffd6f9

Please sign in to comment.