TIme for some debugging. Try debugging your code by adding println() statements to show execution progress and how variable values are changing. For example:
Add a: System.out.println("var=" +...
Type: Posts; User: Norm
TIme for some debugging. Try debugging your code by adding println() statements to show execution progress and how variable values are changing. For example:
Add a: System.out.println("var=" +...
Please copy the full text of the error message and paste it here.
Did you compile and test it to see if it works?
Call it with several different values.
Use a loop like in the size() method to find the Node at the requested location in the list.
Node get(int) returns the Node at the location passed as arg. You were looking for get(0)
The linked list needs a couple of methods:
size() returns the # of nodes in the list
Node get(int) returns the node at int
What happens when you compile and execute the code?
How will that work? It sounds like what an iterator does.
You have got a lot more details of the new method now, but there still are some missing points.
What happens when the end of a list is...
You need to work on the steps of the logic before trying to write code.
What values do the references to the Node objects have that are useful to the program?
Are the lists that are passed to the...
Now you want to forget about the merge() method and work on another project?
You want to work with a method that will take two lists as input, sort each list and then merge the two lists and...
So the copy() method would be in the linked list class and having nothing to do with the class???
It seems like it should be part of the Node class since it is working with Node data.
What would the copy() method do?
Where is a copy made of the contents of the node?
The post code copies a reference to the one node to the other list. So of like this:
String aStr = "asdde";
String bStr = aStr;
bStr and aStr...
That doesn't show that a copy of the node is made. It looks like the original node is moved to List3.
Do you have the steps for making a copy of a node?
I thought that it was returned by merge(). merge() creates it, fills it and returns it.
The more details covered in the design, the fewer problems when writing the code.
The "create a copy" step is missing.
Why is List3 created outside of the merge() method?
That design seems a bit awkward. I'd have the method do the merge in one step.
Step 2 needs some expansion to list the steps required. The way it's worded, it sounds like a clone() method that...
Some class defines the methods of the linked list and holds the pointers to the nodes in the list.
What is the name of that class? Is it HW3_Vinson?
I'm still not sure what the merge method does...
Sorry, that was poorly worded. What is the name of the linked list class the code will be using?
You will need that to define a method that takes list objects as arguments.
Ok, start with that: the method takes two lists as input and returns a new list. What class defines the list?
Then what does the method do?
Ok. Make a list of the steps the merge code needs to do. It needs to include what args it will get when it is called and what it will return.
It sounds like the merge is just a connecting...
Are the lists sorted? Does their order matter when the lists are merged?
Will the old lists be lost when the new list is created or will the nodes in the new list be copied from the old lists?
...
The node at the end of the first list would be connected to the first node of the second list.
Take a piece of paper and draw some nodes for two lists. Connect the nodes in each list with a line...
Set the next pointer at the end of one linked list to the first node in the other linked list.
That will be easy. There are none in java.
The posted code has compiler errors. Do you get...