I'm taking Algorithms I on coursera and came across the implementation of a Data Structure called Bag.
http://algs4.cs.princeton.edu/13stacks/Bag.java.html
However I don't undertand why the use a Node class like this:
private static class Node<Item> { private Item item; private Node<Item> next; } Why is the Item in there? Why can't I use:
private class Node { private Item item; private Node next; } Is there a difference? Thanks
Itemmean in the context of a non-generic world to you? I don't see anywhere that it could be introduced, or what it truly represents. What you've got there is aNodethat holdsItems, whereas the generic is aNodethat can hold literally anything.