import java.util.Iterator;
import java.util.Scanner;

public class ZippableList<Item> implements Iterable<Item> {
    
    private class Node {
        Item item;
        Node next;
    }
   
    private Node first;
    
    public void add(Item item) {   
        Node node = new Node();
        node.item = item;
        node.next = first;
        first = node;   
    }
    
    public Iterator<Item> iterator() {
        return new Iterator<Item>() {
            Node node = first;
            
            public boolean hasNext() {
                return (node != null);
            }
            
            public Item next() {
                Item item = node.item;
                node = node.next;
                return item;
            }
        };
    }
    
    public String toString() {
        String str = "";
        for (Item s : this) {
            str += s + "->";
        }
        return str;
    }
    
    public void zipTogetherWith(ZippableList<Item> list) {
        
        // INSERT CODE HERE ...    
        
    }
        
    public static void main(String[] args) {
        Scanner scanner = new Scanner (System.in);
        System.out.println("Lengths of two lists to be zipped together (separated by a space)? ");
        String[] input = scanner.nextLine().split(" ");
        int thisLength = Integer.parseInt(input[0]);
        int thatLength = Integer.parseInt(input[1]);
        
        ZippableList<Integer> list1 = new ZippableList<Integer>();
        ZippableList<Integer> list2 = new ZippableList<Integer>();
        
        for (int i = 2 * (thisLength - 1); i >= 0; i -= 2) {
            list1.add(i);
        }
        for (int i = 2 * (thatLength - 1) + 1; i >= 0; i -= 2) {
            list2.add(i);
        }
        
        System.out.println("this list : " + list1);
        System.out.println("that list : " + list2);
        System.out.println();
        
        list1.zipTogetherWith(list2);
        System.out.println("after zipping that list into this list...");
        System.out.println("this list : " + list1);
        System.out.println("that list : " + list2);
        
    }
}

