Question: I need help with implementing such an operation for the singlylinked list. For doing this, The following class should be used (DoubleNode, DoublyLinkedList.). As these
I need help with implementing such an operation for the singlylinked 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
![class Doubly LinkedList{ public static void main(String[] args) { DoublyLinked List list](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/02/65bc9a46d5fb8_07865bc9a46b6c50.jpg)


class Doubly LinkedList{ public static void main(String[] args) { DoublyLinked List list = new DoublyLinkedList(); // create empty list // add some elements in the list in reverse order so that list is sorted list.addFirst("W"); list.addFirst("T"); list.addFirst("P"); list.addFirst("L"); list.addFirst("K"); list.addFirst("B"); list.printlist(); list.printReverse(); System.out.println(); System.out.println("change W to X"); list.change Elem("W", "X"); list.printList(); list.printReverse(); System.out.println(); System.out.println("change B to D"); list.change Elem ("B", "D"); list.printList();
Step by Step Solution
3.40 Rating (159 Votes )
There are 3 Steps involved in it
To implement the changeElem method in the DoublyLinkedList class we need to follow the steps provide... View full answer
Get step-by-step solutions from verified subject matter experts
