Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an ArrayListR eview class with one generic type to do the following Creat

ID: 3749110 • Letter: C

Question

Create an ArrayListR eview class with one generic type to do the following Creates anarray list filled with numbers, and inserts new elements into the specified location in the list. Create a method inside the class to implement the calculation of Fibonacdi numbers. Use System.nanoTime to find out how much time it takes to get fab(50) Create a method inside the class to check if an array list is a palindrome, assuming each element in the array list is one character Implement insertionSort either recursively or non-recursively. Implement mergesort using Use System.nanoTime() to find out the speed of your program

Explanation / Answer


package pack3;

import java.util.ArrayList;
import java.util.Arrays;

class ArrayListReview<T>{
T obj;
ArrayList numbers = new ArrayList(Arrays.asList(1,2,3,4,5,6));
//To add elements to list at desired positions
protected void addList(){
numbers.add(2,6);
numbers.add(3,1);
}
public void fab(int n){
int a=0,b=1,c;
System.out.println(a);
System.out.println(b);
while(n!=0){
c=a+b;
System.out.println(c);
a=b;
b=c;
n--;
}
}
public boolean checkPal(){
int length = numbers.size();
for(int i=0;i<length;i++){
int start = (int) numbers.get(i);
int end = (int) numbers.get(--i);
if(length<i){
return true;
}
if(start != end){
return false;
}
}
return true;
}
public void InsertionSort(){
int n = numbers.size();
for(int i=0;i<n;i++){
int key = (int) numbers.get(i);
int j = i-1;
while(j>=0 && key<=(int)(numbers.get(j))){
numbers.set(i+1, numbers.get(j));
j--;
}
numbers.set(j+1, key);
}
}
public void merge(ArrayList<Integer> a, int l, int m, int h){
int flend = m;
int slstart = m+1;
int low=l;
while((low<=flend) && (slstart<=h)){
if(a.get(l) < a.get(slstart)){
l++;
}else{
int temp = slstart;
for(int j=slstart-1;j>=l;j--){
a.set(j+1, a.get(j));
}
a.set(l,temp);
l++;
flend++;
slstart++;
}
}
}
public void mergeSort(ArrayList<Integer> a, int l, int h){
if(l>=h){
return;
}
else{
int m = (l+h)/2;
mergeSort(a,l,m);
mergeSort(a, m+1, h);
mergeSort(a, m, h);
}
}
}
public class NewMain {


public static void main(String[] args) {
long progstarttime = System.nanoTime();
ArrayListReview<Integer> obj = new ArrayListReview<Integer>();
long fabstarttime = System.nanoTime();
obj.fab(50);
long fabendtime = System.nanoTime();
long fabspeed = fabendtime - fabstarttime;
System.out.println("The speed of fab(50) : " + fabspeed);
long progendtime = System.nanoTime();
long progspeed = progendtime - progstarttime;
}
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote