Implement MyUnsortedTableMap class using the PositionalList. public class MyUnso
ID: 3605980 • Letter: I
Question
Implement MyUnsortedTableMap class using the PositionalList.
public class MyUnsortedTableMap<K, V> extends AbstractMap<K,V>{
private PositionalList<MapEntry<K,V>> table = new LinkedPositionalList<>();
@Override
public int size() {
// TODO Auto-generated method stub
return 0;
}
@Override
public V get(K key) {
// TODO Auto-generated method stub
return null;
}
@Override
public V put(K key, V value) {
// TODO Auto-generated method stub
return null;
}
@Override
public V remove(K key) {
// TODO Auto-generated method stub
return null;
}
@Override
public Iterable<Entry<K, V>> entrySet() {
// TODO Auto-generated method stub
return null;
}
}
Explanation / Answer
import java.util.Random;
public class Main {
public static void main(String[] args) {
Random rand = new Random();
PositionalList<Integer> a = new LinkedPositionalList<Integer>();
int Low = 1;
int High = 20;
int n = rand.nextInt(High - Low) + Low;
System.out.println(n);
// iterate through for loop n times, to add n elements into the list
// to add an element, use insert method
for (int i = 0; i < n; ++i) {
int low = 1;
int high = 100;
int list = rand.nextInt(high - low) + low;
System.out.print(list);
a.insert(list); // inserting integer 'list' into the PositionalList 'a'
}
System.out.println(a); // prints the list
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.