I have to create a linked list in java to take a text file and create a list. Th
ID: 3829188 • Letter: I
Question
I have to create a linked list in java to take a text file and create a list. The assignment dub "you are a newly hired consultant and your job is to ugrade the program for stoargae and retreivael"
Utilize Skip List implementation
Highest Level list will represent the first 3 numbers in hundreds (0-099, 100=199, etc)
Second level list will represent the tens (00, 010. 020. 090, 100.....980,990)
Third level list will represent the singles (000, 001....100, 101, 998, 999)
Fourth level list will represent each serial number using the last 6 digits.
You would used the insertion sort method
Any help? I have the single link list sample that has to be converted to skip list
The database.txt look list this (It a big list so here just a few, they are all fake SSN of course)
510421600;Shelley;Morgan
790701850;Holton;Jose
932371897;Hynes;Naomi
714797789;Kunkel;Dylan
878566780;Grisham;Ellie
810639750;Childs;Lillian
Explanation / Answer
public class PatientList<T> implements ListInterface<T>{
protected int numOfElements;
protected LLNode<T> currentPos;
protected boolean found;
protected LLNode<T> location;
protected LLNode<T> previous;
protected LLNode<T> list;
protected LLNode<T> tail;
public PatientList()
{
numOfElements = 0;
list = null;
currentPos = null;
}
public void add(T element)
{
LLNode<T> newNode = new LLNode<T> (element);
newNode.setLink(list);
list = newNode;
numOfElements++;
}
protected void find(T target)
{
location = list;
found = false;
while(location != null)
{
if(location.getInfo().equals(target))
{
found = true;
return;
}
else
{
previous = location;
location = location.getLink();
}
}
}
public int size()
{
return numOfElements;
}
public boolean contains(T element)
{
find(element);
return found;
}
public boolean remove(T element)
{
find(element);
if(found)
{
if(list == location)
list = list.getLink();
else
previous.setLink(location.getLink());
numOfElements++;
}
return found;
}
public T get(T element)
{
find(element);
if(found)
return location.getInfo();
else
return null;
}
public String toString()
{
LLNode currNode = list;
String listString = "List: ";
while(currNode != null)
{
listString = listString + " " + currNode.getInfo() + " ";
currNode = currNode.getLink();
}
return listString;
}
public void reset()
{
currentPos = list;
}
public T getNext()
{
T next = currentPos.getInfo();
if (currentPos.getLink() == null)
currentPos = list;
else
currentPos = currentPos.getLink();
return next;
}
}