Advertisement
jtentor

LinkedList 1er parte - DemoSimpleLinkedList.java

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