Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Created by Julio Tentor <jtentor@fi.unju.edu.ar>
- //
- import java.util.LinkedList;
- import java.util.Random;
- public class DemoList3 {
- public static void main(String[] args) {
- System.out.println("Demo de lista enlazada librería estándar");
- Random random = new Random();
- LinkedList<Integer> lista1 = new LinkedList<Integer>();
- LinkedList<Integer> lista2 = new LinkedList<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();
- for (Integer element: lista1) {
- System.out.printf("%d ", element);
- }
- System.out.println();
- System.out.print("Lista2.: ");
- //lista2.Mostrar();
- for (Integer element: lista2) {
- System.out.printf("%d ", element);
- }
- System.out.println();
- 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();
- for (Integer element: lista1) {
- System.out.printf("%d ", element);
- }
- System.out.println();
- System.out.print("Lista2.: ");
- //lista2.Mostrar();
- for (Integer element: lista2) {
- System.out.printf("%d ", element);
- }
- System.out.println();
- System.out.print("Extrae el último hasta vaciar la lista1: ");
- while (lista1.size() != 0) {
- System.out.printf("%d ", lista1.removeLast());
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement