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 DemoList4 {
- public static void main(String[] args) {
- System.out.println("Demo de lista enlazada simple con iterador");
- Random random = new Random();
- SimpleLinkedListIterator<Integer> lista1 = new SimpleLinkedListIterator<Integer>();
- SimpleLinkedListIterator<Integer> lista2 = new SimpleLinkedListIterator<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