1.This lab is a multi-file project on linked lists. You have been given
These have most of the necessary components for a linked list. The only missing pieces are LnkLst insert methods such as insHead, insPos, insTail. All these methods return an int representing the number of nodes remaining after the insertion. insPos also accepts a int argument representing the index at which the node to be inserted. Unlike the other insert methods, if the int argument representing the index at which the node is to be inserted is outside the range of possible indices for the current list, -1 (a public static final int constant in LnkLst called FAILURE) is returned.
In addition, you are to add two additional LnkLst methods, lSearch and createFromFile. The method lSearch returns an int and accepts a final Data meant to represent a Data instance containing the search SSN. This function begins at the head of the list and sequentially searches through it using the input Data instance. If it finds a match, the list is left at that position and returns the index at which the record was found; otherwise, the list is repositioned to where it was before the search began AND -1 (use the same constant as just mentioned) is returned.
On the other hand, createFromFile accepts a String representing a file name. The file will be binary and contains the same randomized information as you have seen in previous exercises. This method reads the file one record at a time and then inserts each record into the tail of the linked list. It returns the number of records in the linked list and -1 in case of failure (use the same constant as just mentioned).
To make use of your implementation of the linked list, a driver, Lab06.java must be created. It is very much like the ones you have created for earlier assignments. It continuously re prompts the user for an input file name after which it calls createFromFile. Upon returning and only if the status is successful, the driver continuously re-prompts the user to enter a search SSN that is used in the call to lSearch. If a valid found index is returned, the toString method of the Data class is invoked and an appropriate message is printed to the screen. This message includes the time required for a successful search; otherwise, the user is informed that their SSN was not found.
Be sure to remember the general rules of good program construction. Your output should appear as follows:
Enter the file you want read - C:\LAB.dB
C:\LAB.DB could not be opened.
Do you wish to continue (Y/N)? – y
Enter the file you want read - Lab06.bin
Lab06.bin could not be opened.
Do you wish to continue (Y/N)? - y
Enter the file you want read - unSortedData.bin
Preparing to read unsortedData
unsortedData.bin has 1000000 records.
Enter the search SSN (no separators please) - 7Yuv4dxjp
Searching for SSN 7Yu-v4-dxjp
SSN 7Yu-v4-dxjp was not found.
Do you wish to search for another record (Y/N)? - y
Enter the search SSN (no separators please) - C5f*y"WT>
Searching for SSN C5f-*y-"WT>
The key was found in record # 999999.
The linear search required 87 ms to complete.
SSN = C5f-*y-"WT>
fName = < $5D|W]/0kGBWHL)`d*
mName = d
lName = {|(1!iXRlr+"0R]kk9!rF&ao1,C+Uq
addr = F&sy\?^+hl35%b=E:1K"|TL,[F#Mj;J=KTU5/I,E
city = o$_WI_xhNydCT^K@zYq9
state = &U
zip = oY0]-,SCA
Do you wish to continue with another SSN (Y/N)? – n
Do you wish to continue with another file (Y/N)? - n
In order to be more object-oriented and foster re-use in future linked list labs, consider the following implementation. Create the abstract base class BaseLnkLst which contains
Then extend that class via inheritance to form LnkLst. LnkLst implements its own createFromFile method as described in the lab specification and all of the insert methods you were asked to implement. Use LnkLst as you were asked to in the original specification. You will see that this will assist you in the next lab on sorted linked lists.