Karen Byk wrote:I am working on an assignment that requires me to implement 2 methods (add() and remove()) and create an inner class (OrderedListNode). I must use data items of type Comparable. The items should be sorted.
I understand what needs to be done, but I am having a difficult time actually writing the code.
I added the main method to check to see if my code works
Karen Byk wrote:I didn't write all of the code - just add() remove() and OrderedListNode class.
My problem is translating it from English.
I tried it as another class, but it didn't work so I threw it in with the program I'm working with. It doesn't even print the
Karen Byk wrote:My problem is translating it from English.
Mike. J. Thompson wrote:
How did you compile your code, and how are you trying to run it?
What happens when you run it?
Karen Byk wrote:I was told that the head and tail nodes are null, so everything should be between them. So if I wanted to add ‘b’ to my linked list and nothing was in it, it would be head -> b -> tail
Karen Byk wrote:
I use JGrasp - most people have never heard of it, it is somewhat similar to eclipse I guess.
Nothing happens when I run it.
----jGRASP exec: javac -g OrderedLinkedList.java
Note: OrderedLinkedList.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
----jGRASP: operation complete.
but that shouldn't cause any issues since it is just a warning.
Winston Gutkowski wrote:
Yes, but it also has to be head ← b ← tail; and right now you don't appear to be doing that. You need to update both sets of pointers, not just the forward ones.
One thing that might help you: Rather than putting all your add and remove logic in the list, why not put it in your Node class?
Mike. J. Thompson wrote: Alternatively you might want to compile and run using javac and java on the commandline to eliminate JGrasp from the equation until you become more familiar with it.