Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Node {
- public String data;
- public Node next;
- public Node(String data)
- {
- this.data = data;
- }
- public void displayNode()
- {
- System.out.println(data);
- }
- }
- //LISTA
- class Lista {
- Node first = null;
- public String addFirst(String data) {
- Node newFirst = new Node(data);
- newFirst.next = first;
- first = newFirst;
- return first.data;
- }
- public String removeFirst() {
- Node oldFirst = first;
- first = first.next;
- return oldFirst.data;
- }
- public boolean isEmpty() {
- return first == null;
- }
- public String firstElem()
- {
- return first.data;
- }
- public void displayList()
- {
- Node current = first;
- while (current != null)
- {
- current.displayNode();
- current = current.next;
- }
- }
- }
- //STOS
- class Stos {
- private final Lista lista = new Lista();
- public String push(String data)
- {
- return lista.addFirst(data);
- }
- public String pop() {
- return lista.removeFirst();
- }
- public boolean isEmpty() {
- return lista.isEmpty();
- }
- public String toString() {
- return lista.toString();
- }
- public String peek()
- {
- return lista.firstElem();
- }
- public void display()
- {
- lista.displayList();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement