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

    Default problem with my bucket sort

    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;

    /**
    *
    * @author sss
    */
    public class tryyyy444 {

    //method BUCKET_SORT(A)
    public static int[] bucketSort(int[] A, int n){


    //let B[0 .. n – 1] be a new array
    int[][] B = new int[A.length-1][5];

    //for i = 0 to n – 1
    //make B[i] an empty list;
    for (int i=0; i<B.length; i++){
    B[i][5]=0;
    }

    //for i = 1 to n
    // insert A[i] into list B[ floor(n . A[i]) ];

    for (int i=0; i<A.length; i++){
    // B[A[i]]++;
    int t = (int) Math.floor(n*A[i]);
    B[t][5] = A[i];
    }
    ///============================= insertion Code ====
    // for i = 0 to n – 1
    //sort list B[i] with insertion sort;
    //================================================== ==

    for (int j = 1; j < B.length; j++) {
    int key;
    int i;
    key = B[j][5];
    i = j - 1;
    while (i >= 0 && B[i][5] > key) {
    B[i + 1] = B[i];
    i = i - 1;
    // count++;
    }
    B[i + 1][5] = key;


    //concatenate the lists B[0], B[1], …, B[n-1] together in order;
    int [] C = new int[i];
    key = C[i];
    }
    return A;
    }

  2. #2
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

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

    Default

    any one have any idea?

  4. #4
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

    Default

    Yes, I have plenty of ideas.

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

    Default

    ideas of what?

    I need a help on this code

  6. #6
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

    Default

    Quote Originally Posted by someone View Post
    ideas of what?
    On various things.

    Quote Originally Posted by someone View Post
    I need a help on this code
    Your need is noted.

    Any more questions?

  7. #7
    snotmare is offline Member
    Join Date
    Apr 2011
    Posts
    34
    Rep Power
    0

    Default

    What exactly is the problem? You might get better responses here if you provided more details of what you need help with.

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

    Default

    Hello

    I tried to implement a bucket sort program using 2D array:


    I modify it more:

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package assignment3;

    /**
    *
    * @author sssss
    */
    public class mybookbucketsort {


    public static int[] bucketsort(int [] A, int c){

    int rows=A.length;
    int [] bucket=new int [5];
    int columns= bucket.length;
    int [][] B= new int [rows][columns];

    for( int i=0 ; i<rows-1 ; i ++){
    for( i=1 ; i<columns ; i ++){

    B[rows][columns]=0;
    }
    }
    for (int i=0; i<A.length; i++){
    // B[A[i]]++;
    int t = (int) Math.floor(rows*A[i]);
    B[rows][columns] = A[t];
    }



    // ====== insertion sort

    for ( int i=0 ; i< B.length ; i++){

    int key;
    for (int j = 1; j < c; j++)
    {
    key = B[rows][columns];
    i = j - 1;
    while (i >= 0 && B[rows][columns] > key)
    {
    B[i + 1] = B[i];
    i = i - 1;
    B[rows][columns] = key;
    }
    }
    }

    return A;
    }

    public static void main(String[] args) {

    int [] A = { 1,3,4,5};
    bucketsort(A, 3);
    System.out.println();
    }
    }

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

    Default

    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. bucket sort, list in java
    By someone in forum New To Java
    Replies: 10
    Last Post: 04-12-2011, 12:13 AM
  2. Problem with selection sort
    By Metastar in forum New To Java
    Replies: 6
    Last Post: 10-21-2010, 03:18 AM
  3. Radix Sort Problem !!!!
    By javanew in forum Advanced Java
    Replies: 2
    Last Post: 09-21-2010, 05:33 AM
  4. problem with insertion sort???
    By blueduiker in forum New To Java
    Replies: 2
    Last Post: 03-22-2010, 02:17 PM
  5. Replies: 1
    Last Post: 08-01-2007, 09:55 AM

Posting Permissions

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