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)
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)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images