Starting from:

$25

ECE30862 - HW 9 - Solved



For HW 9 we will write a Java program that defines and  uses a linked list interface to that forces implementors of the interface to support very basic linked list functionality.  The file Main.java contains the main function.  Your code should work with it and produce output similar to what is shown in the file output.txt.  Your code does not have to have the same number of lines listed below, these are basically guidelines to let you know approximately how long the code will be.

You will create three .java files with the following functionality:

MyList.java (6 lines, including blank lines, in my implementation):  This defines the MyList interface, which defines two abstract methods:

public MyList next( ); public void printNode( ); 

IntList.java (20 lines, including blank lines, in my implementation):  This defines the IntList class which implements the MyList interface.  

This class has two fields, next, which is a IntList reference, and data, which is an int.

The class defines a constructor and several functions:

public IntList(IntList n, int data) which adds n to the tail of the linked list. public int getData( ) which returns the value of data;

public IntList next( ) which returns the next node in the linked list.  Note that this is the implementation of public MyList next( ); in the MyList interface. 

public void printNode( ) which uses System.out.print to print the kind of node, and the value of data.  Note that this is the implementation of public void printNode( ); in the MyList interface.

LongList.java (20 lines, including blank lines, in my implementation):  This defines the LongList class which implements the MyList interface.   The functions are very similar to those in IntList.

This class has two fields, next, which is a LongList reference, and data, which is a long.

The class defines a constructor and several functions: public LongList(LongList n, long data) which adds n to the front of the linked list; public long getData( ) which returns the value of data; public LongList next( ) which returns the next node in the linked list;

public void printNode( ) which uses System.out.print to print the kind of node, and the value of data.  Note that this is the implementation of public void printNode( ); in the MyList interface.

More products