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
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
Related questions
Question
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 : 6Input data for node 3 : 7 Input data for node 4: 9
Expert Solution
Step 1
Algorithm:
- Start
- Implement a class Node with attributes data,next which is pointing to next node and prev which is pointing to previous node
- Create a class LinkedList with head as its attribute.
- Implement constructor to Initialize the data
- Implement a method addNode() which adds node to the linked list
- 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
- Implement a function count() which prints the count of number of elements in the list
- Implement a function printList() which prints the list data
- Inside the main method, create object of LinkedList
- Read no.of elements in the list n
- Read n numbers add the data to list by calling addNode()
- Call count() which prints number of elements in the list
- Read the search data
- Call searchNode() by passing search data
- Stop
Step by step
Solved in 4 steps with 2 images
Recommended textbooks for you
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education