Question

Consider the DList class provided in the Week 6 source code archive which stored int data. A common operation on a DList obje
Organizations Help End Methodcione For this question, choose the appropriate pieces of code from the drop down list boxes imp
Consider the DList class provided in the Week 6 source code archive which stored int data. A common operation on a DList object list is to make a copy or clone of list. For example, DList list new DList /I code is here that adds data to list so list is now (1, 2, 3, 4, 5) DList clone = list.clone ( ); // clone is an entirely separate list with the same values as list, İ.e., the /I contents of clone is (1, 2, 3, 4, 5) The pseudocode for clone is: Method clone () Returns DList Declare a new DList named cloneList Declare a Node named traverse making it refer to the first Node in this DList Loop as long as there are Nodes in this DList that remain to be cloned Do Get the int value from traverse and stick it on the end of cloneList Modify traverse to refer to the next node in this DList End Loop Return the clone list End Method clone For this question, choose the appropriate pieces of code from the drop down list boxes that implements clone(). public clone) ( Save All Answ Click Save and Submit to save and submit. Click Save All Answers to save all answers
Organizations Help End Methodcione For this question, choose the appropriate pieces of code from the drop down list boxes implements clone(). public clone () DList Node Save All Answers to save all answers Click Save and Submit to save and submit. Click
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code is as below

public DList clone(){
DList cloneList =new Dlist();
Node traverse = this.head;
while(traverse!=null){
cloneList.add(traverse.getData());
traverse = traverse.next;
}
return cloneList;
}

traverse points to first element of the current list to be cloned. while traverse does not equal null get the data of traverse and add it to the cloneList (assuming the function name is add, it could be append too). traverse point to next node in the list

this can be done separately.

int value = traverse.getData();

cloneList.add(value);

Add a comment
Know the answer?
Add Answer to:
Consider the DList class provided in the Week 6 source code archive which stored int data. A common operation on a DList object list is to make a copy or clone of list. For example, DList list n...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 8.9 Coding lab #5: create a dynamic array ADT and a singly linked list ADT. Honor Code...

    8.9 Coding lab #5: create a dynamic array ADT and a singly linked list ADT. Honor Code Your answers to this homework must be your own work.You are not allowed to share your solutions.You may not engage in any other activities that will dishonestly improve your results or dishonestly improve or damage the results of others. Plagiarism Plagiarism is when you copy words, ideas, or any other materials from another source without giving credit. Plagiarism is unacceptable in any academic environment....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT