Create a class in your personal package for our course named List. The definitio
ID: 3774200 • Letter: C
Question
Create a class in your personal package for our course named List. The definition is given below. We will make all of our List programs a subclass of this class. public abstract class List {public abstract int valueAt(int i); public abstract void append{int x); public abstract void prepend(int x); public abstract void insert(int x, int pos); public abstract void remove(int pos); public abstract int indexOf(int x}; public abstract void set (int x, int pos); public abstract boolean contains(int x); public abstract List subList(int from, int to); public abstract boolean isEmpty(); public abstract int size();} Modify your Linkedlist program so that it is a subclass of the abstract class List. Implement the methods that weren't included in our original LinkedList. Test your methods to make sure they are working correctly. Submit all of your files that reside in your package. (Should be Die, LinkedList, Node, and List)Explanation / Answer
public clas Node {
public int data;
public Node next;
public void getData(int x){
data = x;
}
}
public class LinkedList extends List {
Node start,end;
public int valueAt(int i){
Node temp;
temp = start;
for(int x = 0;x<i;x++)
temp = temp.next;
return temp.data;
}
public void append(int x){
Node temp = new Node();
temp.getData(x);
end.next = temp;
end = temp;
}
public void prepend(int x){
Node temp = new Node();
temp.getData(x);
temp.next = start;
start = temp;
}
public void insert(int x , int pos){
Node temp = new Node();
temp.getData(x);
Node temp1=start;
for(int i = 0; i<pos; i++)
temp1 = temp1.next;
temp.next = temp1.next;
temp1.next = temp;
}
public void remove(int pos){
Node temp =start;
for(int i = 0;i<pos-1;i++){
temp = temp.next;
}
temp.next = temp.next.next;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.