jtentor icon

DemoList1 - DemoList1.java

jtentor | PRO | 06/08/20 03:50:32 PM UTC | 0 ⭐ | 1031 👁️ | Never ⏰ | []
Java |

1.42 KB

|

None

|

0 👍

/

0 👎

// Created by Julio Tentor <[email protected]>
//
import java.util.Random;
 
public class DemoList1 {
    public static void main(String[] args) {
        System.out.println("Demo de lista enlazada simple");
 
        Random random = new Random();
 
        SimpleLinkedList<Integer> lista1 = new SimpleLinkedList<Integer>();
        SimpleLinkedList<Integer> lista2 = new SimpleLinkedList<Integer>();
 
        int num;
        System.out.print("Numeros: ");
        for (int i = 0; i < 6; ++i) {
            num = random.nextInt(101);
            System.out.printf("%d ", num);
            lista1.addFirst(num);
            lista2.addLast(num);
        }
        System.out.println();
 
 
        System.out.print("Lista1.: ");
        lista1.Mostrar();
        System.out.print("Lista2.: ");
        lista2.Mostrar();
 
 
        System.out.print("Extrae.: ");
        for (int i = 0; i < 3; ++i) {
            System.out.printf("%d ", lista1.removeFirst());
            System.out.printf("%d ", lista2.removeLast());
        }
        System.out.println();
 
 
        System.out.print("Lista1.: ");
        lista1.Mostrar();
        System.out.print("Lista2.: ");
        lista2.Mostrar();
 
 
        System.out.print("Extrae el último hasta vaciar la lista1: ");
        while (lista1.size() != 0) {
            System.out.printf("%d ", lista1.removeLast());
        }
        System.out.println();
    }
}

Comments