Advertisement
jtentor

Stack (en Java) de Estructura de Datos - Demo2.java

Sep 20th, 2020
1,912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. //
  2. // Created by Julio Tentor <jtentor@fi.unju.edu.ar>
  3. //
  4.  
  5. public class Demo2 {
  6.     public void Run() {
  7.  
  8.         System.out.println("Demo de Stack (Estructura de Datos y Librería de Java)");
  9.  
  10.         Stack<Character> miPila = new Stack<Character>();
  11.         java.util.Stack<Character> otraPila = new java.util.Stack<Character>();
  12.  
  13.  
  14.         miPila.push('a');
  15.         otraPila.push('a');
  16.         miPila.push('b');
  17.         otraPila.push('b');
  18.         miPila.push('c');
  19.         otraPila.push('c');
  20.  
  21.         System.out.println("miPila..: " + miPila);
  22.         System.out.println("otraPila: " + otraPila);
  23.  
  24.         while (!miPila.empty()) {
  25.             System.out.println(miPila.pop() + " - " + otraPila.pop());
  26.         }
  27.  
  28.         try {
  29.             System.out.println(miPila.peek());
  30.         } catch (Exception e){
  31.             System.out.println(e);
  32.         }
  33.  
  34.         try {
  35.             System.out.println(otraPila.peek());
  36.         } catch (Exception e){
  37.             System.out.println(e);
  38.         }
  39.  
  40.     }
  41.  
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement