Question: [JAVA] help ListArrayMain.java - public class ListArrayMain { public static void main (String[] args) { ListArray L1 = new ListArray(); // constructs the list L1

[JAVA] help

ListArrayMain.java
-
public class ListArrayMain {
public static void main (String[] args) {
ListArray L1 = new ListArray(); // constructs the list L1
L1.InsertBegin(2);
L1.InsertBegin(3);
L1.InsertBegin(7);
L1.InsertBegin(15);
L1.InsertBegin(5);
L1.InsertEnd(666);
L1.InsertAfter(1000,7);
// Now, let's print out the array to verify the insertions worked.
System.out.println("The items in the list are:");
for (int i = 0; i
System.out.println(L1.a[i]);
}
System.out.println("The last cell number is: " + L1.lastCell);
}// end main
}
-
ListArray.java
public class ListArray {
//data fields
int a[]; // holds the lists elements
int lastCell; //index of the last item in the list (array);
//cannot be greater than what the constructor allows
// Constructor
public ListArray() {
a = new int[10]; // sets up array of 10 cells, numbered 0 to 9,
//to hold the elements
lastCell = -1; // indicates an empty list
}
// Methods:
public boolean IsFull() {
if(lastCell==9) {
return true;
} else {
return false;
}
}
public boolean IsEmpty() {
/*if(lastCell==-1) {
return true;
} else {
return false;
}*/
return (lastCell==-1);
}
public void InsertBegin(int item) {
if (IsFull() == false) {
for (int i=lastCell;i>=0;i--) {
a[i+1] = a[i];
}
a[0]=item;
lastCell++;
} else {
System.out.println("list is full");
}
}
public void InsertEnd(int item) {
if (IsFull() == false) {
a[lastCell+1] = item;
lastCell++;
}
}
public void InsertAfter(int item, int datum) {
// insert an item after a specifed datum
int locationOfDatum = Find(datum);
// move list items to the right
for (int i=lastCell;i>=locationOfDatum+1;i--) {
a[i+1]=a[i];
}
a[locationOfDatum+1]=item;
lastCell++;
}
public int Find(int item) {
for (int i=0; i
if (a[i]==item) {
return i;
}
};
return -1;
}
}//end class
-
My question:
-

My question:

-

 [JAVA] help ListArrayMain.java - public class ListArrayMain { public static void

1. Do the following two tasks. Submit the code in ListArrayMain.java that does the following: . In ListArrayMain, construct an array and create the array which is the reversal of the given array and print it out. In ListArrayMain, construct two arrays of the same size and produce an array that "interlaces" them, and prints out the interlaced array. Example if array a consists of data 2, 5, 3, 6 and array b consists of 12,7, 4, 2, then the interlaced array should be 2, 12, 5, 7, 3, 4, 6, 2

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!