Data Structures and algorithms: Topic: Doubly and circular Linked Lists in java: Please solve this on urgent basis: Attach output's picture and explain every statement in commments:   public class DoublyLinkedList {              //Represent a node of the doubly linked list          class Node{           int data;           Node previous;           Node next;                      public Node(int data) {               this.data = data;           }       }              //Represent the head and tail of the doubly linked list       Node head, tail = null;              //addNode() will add a node to the list       public void addNode(int data) {           //Create a new node           Node newNode = new Node(data);                      //If list is empty           if(head == null) {               //Both head and tail will point to newNode               head = tail = newNode;               //head's previous will point to null               head.previous = null;               //tail's next will point to null, as it is the last node of the list               tail.next = null;           }           else {               //newNode will be added after tail such that tail's next will point to newNode               tail.next = newNode;               //newNode's previous will point to tail               newNode.previous = tail;               //newNode will become new tail               tail = newNode;               //As it is last node, tail's next will point to null               tail.next = null;           }       }              //display() will print out the nodes of the list       public void display() {           //Node current will point to head           Node current = head;           if(head == null) {               System.out.println("List is empty");               return;           }           System.out.println("Nodes of doubly linked list: ");           while(current != null) {               //Prints each node by incrementing the pointer.                  System.out.print(current.data + " ");               current = current.next;           }       }              public static void main(String[] args) {                      DoublyLinkedList dList = new DoublyLinkedList();           //Add nodes to the list           dList.addNode(1);           dList.addNode(2);           dList.addNode(3);           dList.addNode(4);           dList.addNode(5);                      //Displays the nodes present in the list           dList.display();       }   }  Using the doubly linked list , implement above and solve  following problem voidcalculateProduct();                                 In this function you should calculate product of every 3rd element and at the end it should return the product For example       Linked List contains Data: 9,8,7,6,5,4,3,2,1,11 Output: 28      Explanation: 7*4*1 = 28

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Data Structures and algorithms:

Topic: Doubly and circular Linked Lists in java:

Please solve this on urgent basis:

Attach output's picture and explain every statement in commments:

 

public class DoublyLinkedList {  
      
    //Represent a node of the doubly linked list  
  
    class Node{  
        int data;  
        Node previous;  
        Node next;  
          
        public Node(int data) {  
            this.data = data;  
        }  
    }  
      
    //Represent the head and tail of the doubly linked list  
    Node head, tail = null;  
      
    //addNode() will add a node to the list  
    public void addNode(int data) {  
        //Create a new node  
        Node newNode = new Node(data);  
          
        //If list is empty  
        if(head == null) {  
            //Both head and tail will point to newNode  
            head = tail = newNode;  
            //head's previous will point to null  
            head.previous = null;  
            //tail's next will point to null, as it is the last node of the list  
            tail.next = null;  
        }  
        else {  
            //newNode will be added after tail such that tail's next will point to newNode  
            tail.next = newNode;  
            //newNode's previous will point to tail  
            newNode.previous = tail;  
            //newNode will become new tail  
            tail = newNode;  
            //As it is last node, tail's next will point to null  
            tail.next = null;  
        }  
    }  
      
    //display() will print out the nodes of the list  
    public void display() {  
        //Node current will point to head  
        Node current = head;  
        if(head == null) {  
            System.out.println("List is empty");  
            return;  
        }  
        System.out.println("Nodes of doubly linked list: ");  
        while(current != null) {  
            //Prints each node by incrementing the pointer.  
  
            System.out.print(current.data + " ");  
            current = current.next;  
        }  
    }  
      
    public static void main(String[] args) {  
          
        DoublyLinkedList dList = new DoublyLinkedList();  
        //Add nodes to the list  
        dList.addNode(1);  
        dList.addNode(2);  
        dList.addNode(3);  
        dList.addNode(4);  
        dList.addNode(5);  
          
        //Displays the nodes present in the list  
        dList.display();  
    }  

Using the doubly linked list , implement above and solve  following problem

voidcalculateProduct();

                                In this function you should calculate product of every 3rd element and at the end it should return the product

For example

      Linked List contains Data: 9,8,7,6,5,4,3,2,1,11

Output: 28

     Explanation: 7*4*1 = 28

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Operations of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education