Question: Starting with the LinkedStringLog class we implemented in class, edit the class to be generic. package stringLog; public class LinkedStringLog implements StringLogInterface { protected LLStringNode

Starting with the LinkedStringLog class we implemented in class, edit the class to be generic.
package stringLog;
public class LinkedStringLog implements StringLogInterface {
protected LLStringNode first = null;
protected LLStringNode foundElement = null;
protected int count =0;
@Override
public void insert(String element){
LLStringNode node = new LLStringNode(element);
node.setNext(first);
first = node;
count++;
}
@Override
public boolean contains(String element){
LLStringNode node = first;
while(node != null && foundElement == null){
if(node.getData().equalsIgnoreCase(element)){
foundElement = node;
}
node = node.getNext();
}
return foundElement != null;
}
@Override
public void remove(String element){
if(first != null && first.getData().equalsIgnoreCase(element)){
first = first.getNext();
count--;
}
else if(contains(element)){
LLStringNode node = first;
while(node.getNext()!= foundElement){
node = node.getNext();
}
node.setNext(foundElement.getNext());
foundElement = null;
count--;
}
}
@Override
public int Size(){
int count =0;
LLStringNode node = first;
while(node != null){
count++;
node = node.getNext();
}
return count;
}
@Override
public void clear(){
first = null;
}
@Override
public boolean isEmpty(){
return (first == null);
}
@Override
public boolean isFull(){
return false;
}
@Override
public String toString(){
String result = "String Log;
";
LLStringNode node = first;
int count =1;
while(node != null){
result += count +"."+ node.getData()+"/n";
node = node.getNext();
count++;
}
return result;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!