Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the two classes below, provide the correct implementation for the deleteSp

ID: 3737316 • Letter: G

Question

Given the two classes below, provide the correct implementation for the deleteSpecificInteger method that allows you to delete a specific integer from the linked list. If there are multiple occurrences of the same integer, then remove all occurrences of that integer.

class Node {

    Node next;

    Integer item;

    public Node(Integer val) {

        item = val;

        next = null;

    }

    public Node(Integer val, Node n) {

        item = val;

       next = n;

    }

}

public class LinkedList {

    Node head;

    public LinkedList(Integer val) {

        head = new Node(val);

    }

    public void append(Integer val) {

        Node tmpNode = head;

        while (tmpNode.next != null) {

            tmpNode = tmpNode.next;

        }

        tmpNode.next = new Node(val);

    }

    public void deleteSpecificInteger(Integer x){

    }

}

Explanation / Answer

//LinkedList .java public class LinkedList { Node head; public LinkedList(Integer val) { head = new Node(val); } public void append(Integer val) { Node tmpNode = head; while (tmpNode.next != null) { tmpNode = tmpNode.next; } tmpNode.next = new Node(val); } public void deleteSpecificInteger(Integer x){ Node tmpNode = head; while (tmpNode.item != x.intValue()) { tmpNode = tmpNode.next; } if(tmpNode != null && tmpNode.next!=null){ tmpNode.next = tmpNode.next.next; } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote