java programming, need write the set,get,add and remove function in the fourque
ID: 3667911 • Letter: J
Question
java programming, need write the set,get,add and remove function in the fourque class
Design and implement a Fourque class that is a List with four fast access points. Both get(i) and set(i,x) must have constant runtime. Both add(i,x) and remove(i) should run in time O(min[i,n?i,|n/3?i|,|2n/3?i|]).
import java. util. AbstractList Fourque: an implementation of the List interface * that allows for fast modifications at the FOUR places * in the list: front, 1/3 in, 2/3 in and the back * Modify the methods so that *set/get have constant runtime k -add/remove have runtime * + minl i, sizeO-i, size/3-il, 12sizeO/3-il) * Oparam the type of objects stored in this list ks/ public class FourqueExplanation / Answer
package codelibraries.chp10;
import java.util.AbstractList;
import java.util.List;
class Fourque <T> extends AbstractList<T>
{
private List<T> arr;
Fourque(List<T> arr)
{
this.arr=arr;
}
@Override
public T get(int i) {
return arr.get(i);
}
@Override
public T set(int i, T x)
{
T oldV = arr.get(i);
arr.set(i, x);
return oldV;
}
@Override
public void add(int i, T e)
{
arr.add(e);
}
@Override
public T remove(int i)
{
return arr.remove(i);
}
@Override
public int size()
{
return arr.size();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.