Question: Write a Java program to simulate ( represent ) a linked list structure using arrays. You will need the following data structures: One Array (

"Write a Java program to simulate (represent) a linked list structure using arrays. You will need the following data structures:
One Array (name it linkedList) that will contain the data in the linked list (e.g. character values: A, B, C, etc...).
Another integer array (name it forwarder) that will serve as a corresponding set of forward ers.
A single external field (integer) named front that will to the front of the linked list (the first element in the list).
A single external field (integer) named rear that will to the rear of the linked list (the last element in the list).
For example,
linkedList:
data array A, B, D, E, F, G, C (Note that the letter 'C' is intentionally left out). Array size is bigger than content.
er array 16345992(after inserting C a XK03 fter B)
public static void insertElement (char y, char x)// insert method header
public static void insertElement (char y)//remove element method header h
So, linkedList [0]= A, linkedList [4]= F, etc...
A variable named front will contain the value 0(the index of the first element)
rear will contain the value 5(the index of the last element, G)
forwarder: 1,2,3,4,5,-(- indicates a er beyond the end of linkedList, or null.)
i.e., forwarder[2] will initially have the value 3, which s to linkedList[3], or the value E You can read this as: the element in linkedList indexed by 2 s to the element in linkedList indexed by 3. Note that the value 3 in forwarder is then itself used as an index in the array linkeList to to the next element in the list.
Within your program, provide methods that will perform the following functions:
insertElement(afterElement, newElement) that will insert an element anywhere within the middle of the linked list (not before the front or after the rear).
removeElement(elementValue) that will remove (delete) an element from the middle of the list (not the front or the rear)
For example, if you wanted to insert the element C after B in the array linkedList, you would simply add an element of value C to the end of the linkedList array, and then manipulate the forwarder array accordingly. After the insert operation, the two arrays should result in the following configuration:
linkedList: A, B, D, E, F, G, C
forwarder: 1,6,3,4,5,-,2,
Note that the array elements themselves are not moved from their original positions in the array. The inserted element (C) is simply added at the end of the array ( position 6), and then the forwarder array is updated accordingly: linkedList [1](element B) is now ing to element linkedList[6] instead of linkedList[3]. Note also that the newly inserted element (C) now s to position 2 in the linkedList array.
It is left as an exercise for the student to determine the steps involved in a removeElement(elementValue) operation.
(Please don't copy/paste from previous chegg answers, I'm looking for original work, thanks)"

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 Programming Questions!