Last active
November 22, 2018 11:29
-
-
Save klenne/73f40d7b5507dc5402a1d6aac5d10ffd to your computer and use it in GitHub Desktop.
This file contains 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
package pilha; | |
import java.util.Scanner; | |
/** | |
* @author Klenne | |
* | |
*/ | |
public class Pilha { | |
int vet[] = new int[100]; | |
int topo = -1; | |
Scanner s = new Scanner(System.in); | |
public void mostra() { | |
if (topo < 0) { | |
System.out.print("A pilha está vazia\n"); | |
} else { | |
System.out.println("\n Mostrando a pilha:\n"); | |
for (int i = topo; i >= 0; i--) { | |
System.out.println(vet[i]); | |
} | |
} | |
} | |
public void empilha() { | |
System.out.println("Digite o número para empilhar:"); | |
topo++; | |
vet[topo] = s.nextInt(); | |
mostra(); | |
} | |
public void desempilha() { | |
if (topo <0) { | |
System.out.print("A pilha está vazia\n"); | |
} else { | |
topo--; | |
mostra(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment