jtentor

DemoList2.java [lista doble]

Oct 22nd, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class DemoList2 {
  4.  
  5.     public static void main(String[] args) {
  6.         System.out.println("Demo de listas dobles");
  7.  
  8.         Random random = new Random();
  9.        
  10.         List<Integer> lista1 = new List<Integer>();
  11.         List<Integer> lista2 = new List<Integer>();
  12.        
  13.         int num;
  14.         System.out.printf("\nNumeros: ");
  15.         for (int i = 0; i < 6; ++i) {
  16.             num = random.nextInt(1000);
  17.             System.out.printf("%d ", num);
  18.             lista1.AddFirst(num);
  19.             lista2.AddLast(num);
  20.         }
  21.        
  22.         System.out.printf("\n\nLista1: ");
  23.         lista1.Mostrar();
  24.        
  25.         System.out.printf("\nLista2: ");
  26.         lista2.Mostrar();
  27.  
  28.  
  29.         System.out.printf("\n\nExtrae: ");
  30.         for (int i = 0; i < 3; ++i) {
  31.             System.out.printf("%d ", lista1.RemoveFirst());
  32.             System.out.printf("%d ", lista2.RemoveLast());
  33.         }
  34.  
  35.         System.out.printf("\nLista1: ");
  36.         lista1.Mostrar();
  37.        
  38.         System.out.printf("\nLista2: ");
  39.         lista2.Mostrar();
  40.  
  41.         System.out.printf("\n\nExtrae el último hasta vaciar la lista: ");
  42.         while (lista1.getCount() != 0) {
  43.             System.out.printf("%d ", lista1.RemoveLast());
  44.         }
  45.        
  46.        
  47.     }
  48.  
  49. }
Add Comment
Please, Sign In to add comment