In: Computer Science
java program
public class FavoriteList {
protected PositionList> fList; // List of entries
/** Constructor; O(1) time */
public FavoriteList() { fList = new NodePositionList>(); }
// Complete your work and write out a main function to test
top, access and remove methods.
}
In order to provide you the correct answer, you would need to provide me the implementation of class NodePositionList and PositionList classes.
Since you have not provided any of them, I am providing a sample implementation which may not be correct.
CODE
===============
public class FavoriteList {
protected PositionList<Integer> fList; // List of entries
/** Constructor; O(1) time */
public FavoriteList() {
fList = new NodePositionList<Integer>();
}
// Complete your work and write out a main function to test
public static void main(String[] args) {
for (int i=0; i<10; i++) {
fList.add(i);
}
System.out.println("Top element is: " + fList.top());
System.out.println("The elements present in the list are: ");
for (int i = 0; i<fList.size(); i++) {
System.out.print(fList.get(i) + " ");
}
System.out.println("Removing 5 from the list....");
fList.remove(5);
System.out.println("Now, the elements present in the list are: ");
for (int i = 0; i<fList.size(); i++) {
System.out.print(fList.get(i) + " ");
}
}
}