Now print out TestList.java and study the code. There are seven lines marked with numbers (//**** 1 ****, etc). For each of these lines, draw a diagram like those in Chapter 4 of the text showing front and temp and everything they refer to. Your diagrams should show the structures after the line executes. Draw the diagrams on the TestList printout.
In the first strategy, each time you add to the end of the list you assign a temporary pointer to the front of the list and move it along until it reaches the last node. You know when it's at the end because the next field of the last node is null. Once you find the last node, you can change its next field to point to the new node.
Copy TestList.java into TestList1.java and use this strategy to add each node to the end of the list instead of the beginning. Note that inside your loop that adds the nodes you'll need another loop to find the end of the list each time.
What is the big-Oh complexity of adding a node this way?
Write and explain your
answer using comments at the top of the code.
Copy TestList.java into TestList2.java and use this strategy to add each node to the end of the list instead of the beginning.
What is the big-Oh complexity of adding a node this way?
Write and explain your
answer using comments at the top of the code.