Ranajoy Saha wrote:Are there any LinkedList tutorials that I could follow?
Ranajoy Saha wrote:But could someone please explain how this statement works, "System.out.println("Next Link: " + theLink.next);", I'm still unable to figure out how this corresponds to the OUTPUT this program provides.
Winston Gutkowski wrote:For example, I have a single-linked implementation called 'Ring' that I use all the time, which is a circular linked list with a sentinel node, which has a few advantages:
J. Kevin Robbins wrote:Excuse me for hijacking this thread. I can split this off if needed. But I'm curious what you use this class for "all the time". I've never even had the need to use a Linked List so I'm at a loss to understand what this Ring class is for.
J. Kevin Robbins wrote:I've never even had the need to use a Linked List so I'm at a loss to understand what this Ring class is for.
Knute Snortum wrote:"Practice@659e0bfd" is the output of the toString() method of the Object class, which is the superclass of all classes. In order the get your own toString() method, you need to override Object's. Try this and post your code.
That @Override was not added by me, I use NetBeans IDE, the IDE was giving me an Warning "Add @Override Annotation", so I added it, but I do not understand the use of it
But, how the does the compiler know, that when I'm calling the objName.ClassType, it must call the toString() method?
Winston Gutkowski wrote:Linked lists are great when you don't know how many elements you're going to create, which is often the case with a Stack or a Queue - you don't know how many elements are going to be pushed into it before you start popping elements off - from either end. It only takes as much space as is needed; albeit that each element takes up a bit more space. If I used an array (or an ArrayList), I'd have to "guesstimate" how much space I need and then re-allocate if I run out of room.
linked lists provide O(1) insertion and deletion from one end - and in the case of a ring with a sentinel, from both ends (you either add after the sentinel, or you replace the sentinel with a value and add a new one).
Ranajoy Saha wrote:But, how the does the compiler know, that when I'm calling the objName.ClassType, it must call the toString() method?
That @Override was not added by me, I use NetBeans IDE, the IDE was giving me an Warning "Add @Override Annotation", so I added it, but I do not understand the use of it.
Stephan van Hulst wrote:If memory serves, LinkedList is doubly linked, and has constant time for getting the last element. Also, ArrayList has amortized constant time for addition, and in practice is usually faster than LinkedList with most operations.
Winston Gutkowski wrote:and much easier to make Thread-safe.