Question: Write the code for the method named remove2 in the file Arrays.java where the number of lines is less than the method we wrote together

Write the code for the method named "remove2" in the file Arrays.java where the number of lines is less than the method we wrote together in class

* *PLEASE DON'T USE HANDWRITING

public class Arrays{ private int[] array;

Arrays(int capacity){ array = new int[capacity];

}

public void remove(int index){ int[] temp = new int[array.length - 1]; for(int i = 0; i < index; i++) temp[i] = array[i]; for(int i = index; i < array.length - 1; i++) temp[i] = array[i + 1]; array = temp; } public void remove2(int index){ //write your code here }

public void removeFromFront(){ int[] temp = new int[array.length - 1]; for(int i = 1; i < array.length; i++) temp[i - 1] = array[i]; array = temp; } public void removeFromEnd(){ int[] temp = new int[array.length - 1]; for(int i = 0; i < array.length - 1; i++) temp[i] = array[i]; array = temp; } public void insert(int x){ int[] temp = new int[array.length + 1]; int i; for(i = 0; i < array.length && array[i] < x; i++) temp[i] = array[i]; temp[i++] = x; for(; i < temp.length; i++) temp[i] = array[i - 1]; array = temp; } public void addToEnd(int x){ int[] temp = new int[array.length + 1]; for(int i = 0; i < array.length; i++) temp[i] = array[i]; temp[temp.length - 1] = x; array = temp; } public void addToFront(int x){ int[] temp = new int[array.length + 1]; temp[0] = x; for(int i = 0; i < array.length; i++) temp[i+1] = array[i]; array = temp; } @Override public String toString(){ return java.util.Arrays.toString(array); }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!