I am trying to create my own style of Bucket Sort and I am getting an error with my code and I don't know how to fix it. Any help would be great. I have two classes, Node and BucketSort:
public class Node {
protected int element;
protected Node next;
public Node()
{
element = 0;
next = null;
}
public Node getNext(Node n)
{
return next;
}
public void setNext(Node n)
{
n = next;
}
public void setElement(int e)
{
e = element;
}
public int getElement()
{
return element;
}
}
and
public class BucketSort extends Node{
public static void bucketSort(int v, int[] b) //b = the array of integers and v = number of buckets wanted.
{
Node[] bucket = new Node[v]; //Creating an array of type Node called bucket with v buckets.
for (int i=0; i<=b.length; i++){
bucket[i].setElement(b[i]); //Loop through array of integers b, and set each element to the corresponding index of array bucket.
return;
}
for (int i=0; i<=bucket.length; i++){
//Getting the element at the indexed Node of array "bucket" and assigning it to the array "b" at location element-1. For example if the element is 3, then 3 is assigned to index 2, since it is the 3rd spot.
b[getElement()-1] = bucket[i].getElement();
return;
}
System.out.println(b);
}
}
I am getting the following Error at line 16 of BucketSort, the is code: b[getElement()-1]
The Error is:
Cannot make a static reference to the non-static method getElement() from the type Node.
Can you please tell me how to fix this.
Thanks
How can I Test This Program?