This lab will help you learn more about linked lists as well as classification. in the package intList you will develop a new class orderedIntList that extends intList and enables us to maintain a list of value in ascending order.
cd public-html/classes/csc241
cp -r /csclass/mohammad/public-html/classes/csc241/intList .
-- don't forget the dot or the -r. This command replicates my intList directory and places it in your account.
The following should be used as a template in creating this new class. Note that the other methods from intList are simply inherited as well as the variables current_ and header_.
public class orderedIntList extends intList { public orderedIntList() { super(); } public void insert( intx ) { /* if list is empty || x is smaller than element_ in header_ construct a listNode with header_ referencing it with x and header_ as parameters. Have Current_ also reference this new node. return. node temp=header_; while (temp.next_ != null && x is larger than element_ in temp.next_) temp=temp.next_; construct a node with temp.next_ referencing it with x, and temp.next_. Have Current_ also reference this new node. return. */ } public void insertAtBeginning( int x ) { /*Do Nothing--insertAtBeginning will act as no-op for this class */ } }
Using test1.java and test2.java as models develop test programs for orderedIntList. Make sure normal as well as boundary cases are tested. Boundary cases are insertions that insert in front or at the end as the value inserted causes that to occur. Here is output from my orderedtest1.java:
java orderedtest1
Use insertAtBeginning to insert1, then 3,2,6,9, and 5
Content After All Inserts: head-> 2-> 3-> 5-> 6-> 9->
The value in the current node is 5
The value in the next node is 6