linked list - Implementing a Set in Java using a LinkedList -


i have create class named myset includes methods isempty(), insert(object o) etc. thought use linked list of objects implement myset class. new java, stuck creating object i.e. not clear how start with. thought of this:

public class myset {     linkedlist<object> ll = new linkedlist<object>();  } 

i further have write method: public myset union(myset a): returns set union of current set set a. can done iterating through a, if element @ particular index in not contained in ll add element ll. how write in java code?
ps: assignment question , aren't allowed use sets implementation.

some starting points.

you should either use "true" generics:

class myset<t> {   private final linkedlist<t> objects = new linkedlist<t>(); 

or leave generics out, like:

class myset {   private final linkedlist objects = new linkedlist(); 

you see, solution

linkedlist<object> ll = new linkedlist<object>();  

will allow user can store any kind of object in set. so, first string, integer, , on. likely, not had in mind. in general, collections in java specific sort of objects, strings, or integer objects.

( side note: ll bad name field - study java naming guide lines that, )

but there less sense in use <object>. using generics without using them @ same point.

and now, have myset class, start 1 one:

  1. you add constructor allows instantiating object of class
  2. you add methods (one one!) allow reasonable interaction class

thing is: start slowly. dont try solve big things upfront. instead: make sure class works set; can add things, can check in; , on.

and when of these basic things work should go forward , add stuff "union".


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -