Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

imageimageimageimage

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Statistics In Practice

Authors: Bruce Bowerman, Richard O'Connell

6th Edition

0073401838, 978-0073401836

More Books

Students also viewed these Programming questions

Question

7. What is the function of Golgi tendon organs?

Answered: 1 week ago