0

I'm trying to get my head round the bucketsorting algorithm, but failed to do so.

Looked at numerous examples... but can't get it working...

Let's say I have this:

public class Employee {
     int id; /// example: 52015
     String firstname,lastname;
     String department;

}

I have a huge list of employees, I then strip the list of all employees to sublists for each department. And the goal is to bucketsort these lists, on employee id. So I have my arraylists of employees, ready to pass on. I just can't seem to understand it.

THANK YOU!

robkriegerflow
  • 708
  • 5
  • 13
WordPressGuy
  • 97
  • 1
  • 6

1 Answers1

1

Instead of bucket-sorting use Comparable<Employee> interface.

public class Employee implement Comparable<Employee> {
    int id; /// example: 52015
    String firstname,lastname;
    String department;

    public int compareTo(Employee compareEmployee) {
        return this.id - compareEmployee.getID();
    }

Anyway U can read this article to understand this mechanism better.

  • Hi Александр Гончаренко, This is the assignment i'm trying to complete: use for the grouping on department and sorting on employee id a form of bucket-sort. Look at the department as bucket. Which I can't seem to figure out... Though that rules out comparables? – WordPressGuy Oct 10 '14 at 10:01
  • @WordPressGuy, can U write example how do U want to sort. Because for this task (DB of employees) U need to create relational DB or create CRUD with observable pattern. – Alexander Goncharenko Oct 10 '14 at 10:26
  • Hi, check this for some code: http://www.codeshare.io/OwcIc . I couldn't get it all in a comment. – WordPressGuy Oct 10 '14 at 10:46
  • @WordPressGuy, U can sort for any field in each bucket with comparator. – Alexander Goncharenko Oct 10 '14 at 10:59