user623990
user623990

Reputation:

Lost in trying to make a sorting algorithm in Java

I'm lost trying to sort an array of AbstractEvents (which can be of type DailyEvent or WeeklyEvent). They can be sorted either using a DescriptionComparator class, a StartTimeComparator class or a EndTimeComparator class. Events are added to a Planner class in an array to make things simpler.

The planner class has a sort method that accepts an instance of one of the Comparator classes (which implement java's Comparator class) mentioned above. So now I need to figure out a way to sort these events but I'm fairly new to Java and don't get much of the lingo I've seen on certain sites. I'm looking for good old pseudocode with some explanation to know what I'm doing and learn from it.

Thanks to anyone who can help!

Upvotes: 0

Views: 288

Answers (1)

Sherin Syriac
Sherin Syriac

Reputation: 495

I am not sure what you want from the sorting .But I can give you a little bit of explanation.The comparator just gives a way to compare objects.For sorting you would be using utility classes like java.util.Arrays which has a sort method. So your Planner class has an array of Events which needs to be sorted. I guess you can use the Arrays.sort(arrayTobeSorted,comparator) inside the Planner class sort method. The comparator object given here would give the actual order of sorting. For example you have a DescriptionComparator which would sort objects based on description or StartTimeComparator which would sort based on start time.

Hope this helps.In Java there are many utility classes .So basic things like sorting are easy to do.

Upvotes: 1

Related Questions