Hi.
I'm developing a software for my degree project.
I have some problems in sorting the probability item from linkedList object. Here are the snippets of my code (I have almost 400 lines, so if the below is not enough, please let me know)
CLASS LINKEDLIST
class LinkedList implements Comparable
{
private char symbol;
private float probability;
private String codeword;
private LinkedList next;
private int flag;
public int compareTo(Object other)
{
if (this.probability == ((LinkedList) other).probability)
return 0;
else if ((this.probability) > ((LinkedList) other).probability)
return 1;
else
return -1;
}
public LinkedList(char s, float p, String c, int f)
{
symbol = s;
probability = p;
codeword = c;
flag = f;
}
public void setProbability(float p)
{
probability = p;
}
public void setCodeword(String c)
{
codeword = c;
}
public void setFlag(int f)
{
flag = f;
}
public float getProbability()
{
return probability;
}
public int getFlag()
{
return flag;
}
public char getSymbol()
{
return symbol;
}
}
SOMEWHERE INSIDE CLASS TEST
//sort window
public static JPanel getSortWindow(LinkedList linkedList[], int symbolNum)
{
Test sortWindow = new Test();
sortWindow.setVisible(true);
sortWindow.setSize(500,500);
//JPanel newSortPanel = new JPanel(new GridLayout(symbolNum,2));
for(l = 0; l < symbolNum; l++)
{
System.out.println("Symbol: " + linkedList[l].getSymbol() + " Prob: " + linkedList[l].getProbability());
}
Collections.sort(linkedList); //the problem is here
//after sorting
for(l = 0; l < symbolNum; l++)
{
System.out.println("Symbol: " + linkedList[l].getSymbol() + " Prob: " + linkedList[l].getProbability());
}
sortWindow.add(newSortPanel);
return newSortPanel;
}
the error at --> Collections.sort(linkedList);
it says "Cannot find symbol"