

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


import javax.swing.; // for JOptionPane class public class TestIList { / Stand-alone class to test IList union / public static void main(String[] args) { / A list of natural numbers from 1 to 6 / IList naturals = new ConsList(1, new ConsList(2, new ConsList(3, new ConsList(4, new ConsList(5, new ConsList(6, new MTList())))))); IList mt = new MTList(); // empty list / A repetitive list of numbers */ IList repeatList = new ConsList(1, new ConsList(1, new new ConsList ConsList (1,(1, new ConsList (1, new MTList())))));
/* Print original lists / System.out.println(" naturals = " + naturals); System.out.println(" mt = "+ mt); System.out.println(" repeatList = "+ repeatList); / Test the recursive methods on our lists */ System.out.println("\nTesting recursive methods..."); System.out.println(" naturals.length() should be 6 and is " + naturals.length()); System.out.println(" mt.length should be 0 and is "+ mt.length()); System.out.println("\n naturals.contains(4) should be true and is "+ naturals.contains(4)); System.out.println(" naturals.contains(7) should be false and is "+ naturals.contains(7)); System.out.println(" mt.contains(4) should be false and is "+ mt.contains(4)); }