Results 1 to 9 of 9
Thread: problem with my bucket sort
 04112011, 03:21 PM #1Member
 Join Date
 Apr 2011
 Posts
 18
 Rep Power
 0
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.length1][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[n1] together in order;
int [] C = new int[i];
key = C[i];
}
return A;
}
 04112011, 03:31 PM #2Senior Member
 Join Date
 Aug 2010
 Posts
 127
 Rep Power
 0
 04112011, 03:36 PM #3Member
 Join Date
 Apr 2011
 Posts
 18
 Rep Power
 0
any one have any idea?
 04112011, 03:39 PM #4Senior Member
 Join Date
 Aug 2010
 Posts
 127
 Rep Power
 0
Yes, I have plenty of ideas.
 04112011, 03:52 PM #5Member
 Join Date
 Apr 2011
 Posts
 18
 Rep Power
 0
ideas of what?
I need a help on this code
 04112011, 03:55 PM #6Senior Member
 Join Date
 Aug 2010
 Posts
 127
 Rep Power
 0
 04112011, 04:12 PM #7Member
 Join Date
 Apr 2011
 Posts
 34
 Rep Power
 0
What exactly is the problem? You might get better responses here if you provided more details of what you need help with.
 04112011, 05:33 PM #8Member
 Join Date
 Apr 2011
 Posts
 18
 Rep Power
 0
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<rows1 ; 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();
}
}
 04112011, 11:09 PM #9
 Join Date
 Jan 2011
 Location
 Richmond, Virginia
 Posts
 3,069
 Blog Entries
 3
 Rep Power
 8
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

bucket sort, list in java
By someone in forum New To JavaReplies: 10Last Post: 04112011, 11:13 PM 
Problem with selection sort
By Metastar in forum New To JavaReplies: 6Last Post: 10212010, 02:18 AM 
Radix Sort Problem !!!!
By javanew in forum Advanced JavaReplies: 2Last Post: 09212010, 04:33 AM 
problem with insertion sort???
By blueduiker in forum New To JavaReplies: 2Last Post: 03222010, 01:17 PM 
Remove the bucket represented by the int from array
By barney in forum New To JavaReplies: 1Last Post: 08012007, 08:55 AM
Bookmarks