Monday, 12 November 2012

Set Operations using ArrayList

I implemented set operations using only ArrayList and Iterator, which are part of java.util class. Java has its own Set data structure though.
The challenge for this assignment was to use only ArrayList and Iterator. I was trying to implement a BinaryTree data structure based on ArrayList and then implement my set operations on top of that. The worst case running time using ArrayList for most of the operations is O(n^2), while by using BinaryTree they can be done in O(nlog n), worst case. Here I put my code using only ArrayList features. I will make another post about my BinaryTree implementation using ArrayList.
Set class:

Here is the MySet class which implements the Set class:

There was extra mark for efficient running time which I think I won't get any, since the worst case running time for my implementation is O(n^2).
My code passed all the on line tests, however if anybody finds any problem, please leave a comment.

Leo the Pamador

No comments:

Post a Comment