Advertisement
jtentor

DemoList4 - DemoList4.java

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