Assume you are writing code to maintain a linked list. You are to usea variable named head to always point to the first node in the list and the variable named tail to always point to the last node in the list. Write the Java statements required to accomplish each of the following actions given the Node definition above. For the following questions, provide both the lines of code to accomplish the required task (given the restrictions above), and a diagram showing the state of the linked list after all your lines of code (in each question) have been executed. (a) Create a linked list with just a single node that has the value 5 in it. (b) Create and append a node with the value 10 to the end of the list in 1aabove.(c) Using a loop construct of your choice, provide the lines of code requiredto add nodes with the values 15, 20, 25, 30, 35 and 40 in that order to the end of the list in 1b above. (d) Add a node with the value 12 to the list in 1c in its proper positionassuming the list should be maintained an ascending order.(e) Delete the node that contains the value 5 from the linked List in 1d.(f) Using a loop construct of your choice, change the data in each element of the list to be the square of what it was in 1(e)

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

Assume you are writing code to maintain a linked list. You are to use
a variable named head to always point to the first node in the list and the variable named tail to always point to the last node in the list. Write the Java statements required to accomplish each of the following actions given the Node definition above.

For the following questions, provide both the lines of code to accomplish the required task (given the restrictions above), and a diagram showing the state of the linked list after all your lines of code (in each question) have been executed.

(a) Create a linked list with just a single node that has the value 5 in it.

(b) Create and append a node with the value 10 to the end of the list in 1a
above.

(c) Using a loop construct of your choice, provide the lines of code required
to add nodes with the values 15, 20, 25, 30, 35 and 40 in that order to the end of the list in 1b above.

(d) Add a node with the value 12 to the list in 1c in its proper position
assuming the list should be maintained an ascending order.

(e) Delete the node that contains the value 5 from the linked List in 1d.

(f) Using a loop construct of your choice, change the data in each element of the list to be the square of what it was in 1(e)

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Lists
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
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