Anyone help with these 3? 6. public void addFewAtEnd(int howMany, Object element
ID: 3641527 • Letter: A
Question
Anyone help with these 3?6. public void addFewAtEnd(int howMany, Object element)
The addFewAtEnd method adds the parameter element at the end of the linked list for the number of times specified by the parameter howMany. For instance, if the parameter integer is 3, then it should add the parameter Object three times at the end of the linked list. If the parameter integer is less than or equals to 0, nothing should be added to the linked list (so the linked list will be unchanged.)
7.
public void searchAndRemove(Object element)
The searchAndRemove method searches the parameter element in the lined list and removes all occurrences of the element in the linked list. If the parameter element does not exist in the linked list, then the linked list should be unchanged.
8.
public void duplicateEach()
The duplicateEach method duplicates every element in the linked list. For instance, if the linked list contains { Apple Apple Banana Lemon }, then after this method is called, the linked list should become { Apple Apple Apple Apple Banana Banana Lemon Lemon }.
Explanation / Answer
Assuming a linked list class with attributes for a pointer of the next list item (node.next) and another attribute to store the value of a node (node.value), the commented pseudo code can be as follows: 6. public void addFewAtEnd(int howMany, Object element){ node test=new node(); //create a node object to point to and traverse the list test.next=list.head; //get the test node to point to the list object while(test.next!=null) //while loop to get to the end of the linked list test=test.next; //for loop to iterate howMany times at the end of the linked list for(int i=0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.