2. List a . Array based List a.1 Create and Draw an instance of an Array based L
ID: 3537347 • Letter: 2
Question
2. List
a. Array based List
a.1 Create and Draw an instance of an Array based List myListof type ArrayList<String> type. Show the JAVA statements and DRAW 4 objects (String) %u201COne%u201D, %u201CTwo%u201D, %u201CThree%u201D, %u201CFour%u201D (use method add(%u201COne%u201D)).
answer
a.2 Write the JAVA COMPILABLE public method replaceALL with 3 parameters myList, oldItem, and newItem that returns void.
Assume that you have these methods that you can call:
- myList.getLength() returns the size of myList;
- myList.getEntry(index) returns the object at that index;
- myList.replace(index, anItem) void ;sets the object at index to anItem;
/* Replaces each occurrence of oldItem in myList with newItem. */
answer
a.3 Test your code by using the instance that you drew in a.1 by replaceALL "Two" to "Four"
replaceALL(myList, "Two", "Four");
answer
b. Linked based List
b.1 Create and Draw an instance of an Linked based List headof type LinkedList<String> type. Show the JAVA statements and DRAW 3 Nodes containing %u201Chim%u201D, %u201Cher%u201D, and %u201Cit%u201D, and head references the first Node. (use method add(%u201Chim%u201D)).
answer
b.2 Draw the effect of this next following fragment?
Node<String> nodeRef = head.next;
nodeRef.data = %u201Cshe%u201D;
answer
b.3 Draw the effect of the following fragment? (continue from b.2);
Node<String> nodeRef = head.next;
head.next = nodeRef.next;
answer
b.4 Draw the effect of the following fragment? (continue from b.3);
head = new Node<String> (%u201Chis%u201D, head);
answer
Explanation / Answer
your question is not readable at all
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.