Question
need help with implementing such an operation for theDoubylinked list. For doing this, The following class should be used (DoubleNode, DoublyLinkedList.). As these driver classes
need help with implementing such an operation for theDoubylinked list. For doing this, The following class should be used (DoubleNode, DoublyLinkedList.). As these driver classes are making calls to a new method "changeElem", which should have the following signature: void changeElem(String oldStr, String newStr)
I need help with implementing such a method, in the following file: DoublyLinkedList.
Inside this method, you are allowed to call the "search" method at the beginning, to get the node containing the oldStr. But after that, you should not make calls to existing methods.
Here are the steps to help for making the implementing:
? change the value inside that node (hint: you will need to implement a mutator method in the node class) ? if the new value is still smaller than the next node, or if there are no more nodes, then do nothing (stop there) ? disconnect the node from the list for now
? find the new place of the node (by iterating from that point on up until you find its place - next node is larger or we are at the end of the list)
? insert the node at that place
import java.util.*; class DoublyLinkedListIterator DoubleNode current; DoublyLinkedListIterator (DoubleNode node) { current = node;} public String next() // in Iterator interface { String res = null; if (current != null) res = current.getStr(); current = current.getNext();} return res; } else implements Iterator { public boolean hasNext() // in Iterator interface {if (current != null) return true; return false; } { public String prev() { String res = null; if (current != null && current.getPrev() != null) { current = current.getPrev();
Step by Step Solution
3.40 Rating (150 Votes )
There are 3 Steps involved in it
Step: 1
To implement the changeElem method in the DoublyLinkedList class follow these steps Search for the n...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started