Advertisement
jtentor

DemoList2 - DemoList2.java

Jun 8th, 2020
771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. // Created by Julio Tentor <jtentor@fi.unju.edu.ar>
  2. //
  3. import java.util.Random;
  4.  
  5. public class DemoList2 {
  6.     public static void main(String[] args) {
  7.         System.out.println("Demo de lista enlazada doble");
  8.  
  9.         Random random = new Random();
  10.  
  11.         DoubleLinkedList<Integer> lista1 = new DoubleLinkedList<Integer>();
  12.         DoubleLinkedList<Integer> lista2 = new DoubleLinkedList<Integer>();
  13.  
  14.         int num;
  15.         System.out.print("Numeros: ");
  16.         for (int i = 0; i < 6; ++i) {
  17.             num = random.nextInt(101);
  18.             System.out.printf("%d ", num);
  19.             lista1.addFirst(num);
  20.             lista2.addLast(num);
  21.         }
  22.         System.out.println();
  23.  
  24.  
  25.         System.out.print("Lista1.: ");
  26.         lista1.Mostrar();
  27.         System.out.print("Lista2.: ");
  28.         lista2.Mostrar();
  29.  
  30.  
  31.         System.out.print("Extrae.: ");
  32.         for (int i = 0; i < 3; ++i) {
  33.             System.out.printf("%d ", lista1.removeFirst());
  34.             System.out.printf("%d ", lista2.removeLast());
  35.         }
  36.         System.out.println();
  37.  
  38.  
  39.         System.out.print("Lista1.: ");
  40.         lista1.Mostrar();
  41.         System.out.print("Lista2.: ");
  42.         lista2.Mostrar();
  43.  
  44.  
  45.         System.out.print("Extrae el último hasta vaciar la lista1: ");
  46.         while (lista1.size() != 0) {
  47.             System.out.printf("%d ", lista1.removeLast());
  48.         }
  49.         System.out.println();
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement