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

firstNode 59. Repeat question on 12, but instead write the class within a packag

ID: 3909797 • Letter: F

Question

firstNode 59. Repeat question on 12, but instead write the class within a package that contains aion of the ADT bag. Set and get methods will be necessary s necessary to add a node to the beginning of the doubly linked chain. 60. List the steps e step 61. List the steps linked chain. snecessary to remove the first node from 2. If currentNode in the contains method becomes null. the beginning of the doubly t What value does the method return when the bag is not empty public boolean contains(T anEntry) boolean found false; Node currentNode firstNode while (found && (currentNode null)) f if (anEntry.equals(currentNode.data) found true; Lis else currentNode currentNode.next; return found; 63. Trace the execution of the method contains when the bag is empty. What is the result 64. The code that we developed to add a node to an empty chain is Node newNode - new Node(newEntry); firstNode newNode The code that we just developed to add to the beginning of a chain is ode newNode new Node(newEntry); newNode.next = firstNode; firstNode -newNode; Why do these three statements also work correctly when the chain is empty? 65. What steps are necessary to remove the first node in a chain of five nodes? nodes? 66. What steps are necessary to remove the third node in a chain of five 67. Instead of calling the method getRefere nceTo, C could the method of contains Explaiu 1 have called the original definition of cont

Explanation / Answer

               We know that we can traverse in doubly linked list in both direction (Bi-Directional).

       So we should also update the neighbouring nodes. Here is the java code to add a node at the beginning of a doubly linked list.

// Class for Doubly Linked List

public class DLL {

    Node head; // head of list

    /* Doubly Linked list Node*/

    class Node {

        int data;

        Node prev;

        Node next;

        // Constructor to create a new node

        // next and prev is by default initialized as null

        Node(int d) { data = d; }

    }

}

        2.If we want to delete the initial node we should make the initial cancel the pointer pointing to the next node ie the second element in the doubly linked list.

Below is a algorithm to delete the first node in a doubly linked list.

Hope,I have solved your problem.

Thank You :)