Results 1 to 11 of 11
  1. #1
    someone is offline Member
    Join Date
    Apr 2011
    Posts
    18
    Rep Power
    0

    Default bucket sort, list in java

    hello ,

    this is showed error with me in java

    List<double>[] B = new List<double>[10];
    for (int i = 0; i < 10; i++)
    {
    B[i] = new ArrayList<double>();
    }


    why?

  2. #2
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Whats the error? I can't tell you why unless you tell me what error it is.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by someone View Post
    hello ,

    this is showed error with me in java

    List<double>[] B = new List<double>[10];
    for (int i = 0; i < 10; i++)
    {
    B[i] = new ArrayList<double>();
    }


    why?
    You can't create a list of primitives; make that a Double instead of a double and autoboxing will help you.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    someone is offline Member
    Join Date
    Apr 2011
    Posts
    18
    Rep Power
    0

    Default

    the error is with the list

  5. #5
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    JosAH just said what was wrong. Next time post the error message you get when you try to compile the program.

  6. #6
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    a List is an interface and can't be instantiated with new.

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by j2me64 View Post
    a List is an interface and can't be instantiated with new.
    True, but you can instantiate an array of interfaces.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    someone is offline Member
    Join Date
    Apr 2011
    Posts
    18
    Rep Power
    0

    Default

    List<Double>[] B = new List<Double>[10];

    the error about Generic array creation
    any one know why?

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by someone View Post
    List<Double>[] B = new List<Double>[10];

    the error about Generic array creation
    any one know why?
    Generics and arrays don't go well together; change your code to this:

    Java Code:
    List<Double>[] B= new List[10];
    ... or this:

    Java Code:
    List[] B= new List[10];
    This little hack results in a compiler warning that you can safely ignore.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    someone is offline Member
    Join Date
    Apr 2011
    Posts
    18
    Rep Power
    0

    Default

    it worked :)

    another problem with the code is with count!!:

    for (int i = 0; i < 10; i++)
    {
    insertSort(B[i], B[i].count);
    }


    double[] dNew = new double[50];
    int nCurrent = 0;

    for (int i = 0; i < 10; i++)
    {
    for (int j = 0; j < B[i].Count; j++)
    {
    dNew[nCurrent] = B[i][j];
    nCurrent++;
    }
    }

    return dNew;

  11. #11
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    We are not here to do your homework for you. I am going to copy/paste what I said in your other post.

    It's very important that you ask specific questions. Vague questions like "Here is my code, help" will not receive great attention..as you have seen. What is your problem? What doesn't work? How does it not work? What have you done to try to fix it? What does it produce? What were you expecting? Does it compile? If not, what compilation errors did you get(copy/paste EXACT errors, not paraphrasing)? What do you think they mean? What do you think can be done to fix the errors?

    A lot of people here are not going to scan your code and give you the answer unless you put in the effort.

Similar Threads

  1. Insertion Sort for linked list help?
    By bubtub24 in forum New To Java
    Replies: 3
    Last Post: 11-28-2010, 06:21 AM
  2. SORT list on items where frequencies are involved
    By emgee in forum Java Applets
    Replies: 1
    Last Post: 11-14-2010, 02:42 PM
  3. [SOLVED] Insertion Sort in Linked List
    By taylorp in forum New To Java
    Replies: 10
    Last Post: 03-27-2009, 12:34 AM
  4. How to sort a list using Bubble sort algorithm
    By Java Tip in forum Algorithms
    Replies: 3
    Last Post: 04-29-2008, 08:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •