Write a program in Java to manipulate a Double Linked List:   Count the number of nodes Insert a new node before the value 7 of Double Linked List Search an existing element in a Double linked list (the element of search is given by the user) Suppose List contained the following Test Data: Input the number of nodes : 4 Input data for node 1 : 5 Input data for node 2 : 6 Input data for node 3 : 7 Input data for node 4: 9

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

Write a program in Java to manipulate a Double Linked List:

 

  1. Count the number of nodes

  2. Insert a new node before the value 7 of Double Linked List

  3. Search an existing element in a Double linked list (the element of search

    is given by the user)

    Suppose List contained the following Test Data: Input the number of nodes : 4
    Input data for node 1 : 5
    Input data for node 2 : 6

    Input data for node 3 : 7 Input data for node 4: 9

Expert Solution
Step 1

Algorithm:

  1. Start
  2. Implement a class Node with attributes data,next which is pointing to next node and prev which is pointing to previous node
  3. Create a class LinkedList with head as its attribute.
  4. Implement constructor to Initialize the data 
  5. Implement a method addNode() which adds node to the linked list
  6. Implement a method searchNode() which searches for a node with particular data in the list. If the node is present in the list, print node is present else print node is not present
  7. Implement a function count() which prints the count of number of elements in the list
  8. Implement a function printList() which prints the list data
  9. Inside the main method, create object of LinkedList
  10. Read no.of elements in the list n
  11. Read n numbers add the data to list by calling addNode()
  12. Call count() which prints number of elements in the list
  13. Read the search data
  14. Call searchNode() by passing search data
  15. Stop
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
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