Question

public class LinkedIntList public ListNode front; // first value in the list // post: constructs an empty list public LinkedIntList( front null; e public LinkedIntList(int[l arri this); for (int i- 0; i < arr.length; i++)

I need help writing the helper function find() and removeAll(). I'm pretty sure i have find wrong. please help me! I included the top portion of my code so you get an idea of whats going going. on

Java language

someone asked structure of list node too? i dont know what they mean

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public void find(int a ){

ListNode current = front;

while(current!=null && current.next!=null){

if(current.next.data==a){

return current;

}

}

return null;

}

public void removeAll(int a){

ListNode current=null;

current = find(a);

while(current!=null){

current.next = current.next.next; // placing

current = find(a);

}

System.out.println("Removed!");

}

We are finding the node whose next node has the given value

Let the node as x.

if x's next node has the value,find function will return x.

Then removeAll will place the next node of next node in the x's link.

That means that node was deleted from the chain.

public void find(int a ) ListNode current front; while(current!-null && current.next!-null) if(current.next.data-a)l return current; return null; public void removeAll(int a) ListNode current-null; current find(a); while(current!-null)[ current.next current.next.next; // deleting next node by replacing this nodes next with next nodes next current find(a); System.out.println(Removed!);

Add a comment
Know the answer?
Add Answer to:
I need help writing the helper function find() and removeAll(). I'm pretty sure i have find...
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
  • Consider creating a method minToFront that moves the smallest element to the first node in the...

    Consider creating a method minToFront that moves the smallest element to the first node in the list of links in integer values. For example, if the variable list is storing a list of links such as [7, 9, 12, 5, 3, 17], the call to list.minToFront() would be the same as [3, 7, 9, 12, 5, 17]. If there is more than one minimum value, move the first one. If the list is empty, method calls have no effect. The...

  • I need help completing this with C++ /** * Definition for singly-linked list. * struct ListNode...

    I need help completing this with C++ /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* reverseList(ListNode* head) {    } };

  • Doubly Linked List Java Help Details: First, read the DoublyLinkedList.java code and try to under...

    Doubly Linked List Java Help Details: First, read the DoublyLinkedList.java code and try to understand what each field stores and what each method is doing. Modify and complete the class as described below •The field size was defined in the class but was never maintained. Set the current default value and modify it whenever it is needed in the existing methods and other methods you implement as it is needed. It should always include the number of Nodes inside the...

  • Please use Java programming: Modify both ArrayList and LinkedList classes and add the following method to...

    Please use Java programming: Modify both ArrayList and LinkedList classes and add the following method to both classes: public void reverseThisList(), This method will reverse the lists. When testing the method: print out the original list, call the new method, then print out the list again ------------------------------------------------------------------------- //ARRAY LIST class: public class ArrayList<E> implements List<E> { /** Array of elements in this List. */ private E[] data; /** Number of elements currently in this List. */ private int size; /**...

  • Java Double Max Function I need help with this top problem. The bottom is the assignment...

    Java Double Max Function I need help with this top problem. The bottom is the assignment // return Double .NEGATIVE-INFINİTY if the linked list is empty public double max return max (first); h private static double max (Node x) f e I TODO 1.3.27 return 0; 1 package algs13; 2 import stdlib.*; 4 public class MyLinked f static class Node public Node() t 1 public double item; public Node next; 10 int N; Node first; 12 13 14 public MyLinked...

  • Hey I really need some help asap!!!! I have to take the node class that is...

    Hey I really need some help asap!!!! I have to take the node class that is in my ziplist file class and give it it's own file. My project has to have 4 file classes but have 3. The Node class is currently in the ziplist file. I need it to be in it's own file, but I am stuck on how to do this. I also need a uml diagram lab report explaining how I tested my code input...

  • this is part of my code im not sure how to do last 2 function. i...

    this is part of my code im not sure how to do last 2 function. i think above last 2 functions need for making function please help me how to do it. #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include "list.h" typedef struct node { ElemType val; struct node *next; } NODE; struct list_struct { NODE *front; NODE *back; }; int lst_remove_first(LIST *l, ElemType x) { NODE *p; NODE *tmp; if(l->front == NULL) return 0; if(l->front->val == x) {    lst_pop_front(l);...

  • C++ ONLY PLEASE. CAN I GET SOME HELP WRITING THIS HEADER FILE? I MAINLY WANT TO...

    C++ ONLY PLEASE. CAN I GET SOME HELP WRITING THIS HEADER FILE? I MAINLY WANT TO KNOW HOW I WOULD WRITE IT WITH A TEMPLATE. PLEASE AND THANKS IN ADVANCE. **************LinkedList.h requirements************************ linked list Class EXTRA CREDIT OPPORTUNITY: Create the LinkedList class as a template class for 5 extra credit points!!! private memebers Create a structure called ListNode, which should hold a Dinosaur and a pointer to the next ListNode ListNode pointer called head – will eventually point to the...

  • Need help completing my instance method for deleteFront() as specified below To the class IntegerLinkedList, add...

    Need help completing my instance method for deleteFront() as specified below To the class IntegerLinkedList, add an instance method deleteFront such that … Method deleteFront has no input. Method deleteFront returns … an empty Optional instance if the list is empty an Optional instance whose value is the integer that was deleted from the front of the list, otherwise Hints https://docs.oracle.com/javase/10/docs/api/java/util/Optional.html import java.util.Optional; public class IntegerLinkedList { private IntegerNode head ; private int numberOfItems ; public int getNumberOfItems() { return...

  • I need help and have to get this done asap: Using the following source codes provided below, create recursive functions...

    I need help and have to get this done asap: Using the following source codes provided below, create recursive functions and methods in C++ to complete the following exercises: Print the list in forward order Print the list in reverse order Print the following three lines (in this order): "The first node contains <value in first node>" "The last node contains <value in last node>" "The first node contains <value in first node>" Print the sum of all the values...

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