Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pilha;
- public class Node {
- private Node next = null;
- private int value;
- public Node getNext() {
- return next;
- }
- public void setNext(Node next) {
- this.next = next;
- }
- public int getValue() {
- return value;
- }
- public void setValue(int value) {
- this.value = value;
- }
- }
- package pilha;
- public class PilhaDin {
- Node top = null;
- public void push(Node element) {
- if (isEmpty()) {
- top = element;
- }else {
- element.setNext(top);
- top = element;
- }
- }
- public void pop() {
- if (!isEmpty()) {
- top = top.getNext();
- }else {
- System.out.println("Vazia");
- }
- }
- private boolean isEmpty() {
- if (top == null)
- return true;
- return false;
- }
- }
Add Comment
Please, Sign In to add comment