Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Pilha {
- private int topo;
- private int[] dados;
- private int max;
- public Pilha(int max) {
- this.max = max;
- this.topo = -1;
- criar_pilha(this.max);
- }
- private void criar_pilha(int n) {
- dados = new int[n];
- }
- public int topo() {
- if (topo == -1) return -1;
- else return dados[topo];
- }
- public boolean vazia() {
- if (topo == -1) return true;
- else return false;
- }
- private boolean cheia() {
- if (topo == dados.length - 1) return true;
- else return false;
- }
- public void empilha(int elemento) {
- if (!cheia()) {
- topo = topo + 1;
- dados[topo] = elemento;
- }
- else System.out.println("Pilha cheia");;
- }
- public Integer desempliha() {
- if (!vazia()) {
- int elemento = topo();
- topo = topo - 1;
- return elemento;
- }
- else {
- System.out.println("Pilha vazia");
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment