How do I create the head variable for a linked list? Then implement a set? I have the private inner class Node written. So if I want to create a new linked list using this class, how would I go about doing that? Doing this, I would also need a head variable to start the linked list I'm thinking. I then want to make a set. Is a set the same thing as a standard linked list? class ---- { private class Node { private int value; private Node next; private Node(int value, Node next) { this.value = value; this.next = next; } }
http://docs.oracle.com/javase/6/docs/api/java/util/Set.html http://docs.oracle.com/javase/tutorial/collections/interfaces/set.html
a set is a collection that contains only 1 instance of an element.
Also I really do not know why schools make you learn how to code API's already built, it's a cOMPLETE waste of time. When I was in school in CS 214 Data Structures we had this same thing that was just a waste. We were trying to create our own linked list class, as well as stacks, queues, etc. Completre waste since the Java API LinkedList is already made, and if we needed anything special we could use the interface list, or even extend LinkedList to create our own....
"A set is simply a collection of items in which there are no duplicate items. Thus, A = { 1, 2, 3 } is a set but B = { 1, 1, 3, 5 } is not because 1 appears twice in B. There is no particular order to the items in a set, but we humans like to see the items in sorted order, if possible. " I would like to be able to use the set class, but I have have to write code to make a set as a circular linked list. I just don't know how to successfully make a linked list after making the inner Node class.
Well do you HAVE TO make a linked list? LinkedList a = new LinkedList(); http://docs.oracle.com/javase/1.4.2/docs/api/java/util/LinkedHashSet.html
Honestly I'd just take the Link List's code and change it up if that's what you need.....
Join our real-time social learning platform and learn together with your friends!