How do I do a bubble sort in java, The text file looks like this:
aaa
2
bbb
3
ccc
1
What I need to do is to loop through it and display the highest score to the lowest. When I run the code below, The numbers, are already sorted. and it will display 3, 2, then 1. But the name isn't in sync with the corresponding score, it will only display the names based on what's first. So the output will basically look like this, if I run the code below:
aaa 3
bbb 2
ccc 1
Function:
public void hi_score(){
int i=0;
try {
FileReader fr;
fr = new FileReader (new File("F:\\pscores.txt"));
BufferedReader br = new BufferedReader (fr);
int ar=0;
for(ar=0;ar<10;ar++){
player_name[ar]=br.readLine();
player_score[ar]=Integer.parseInt(br.readLine());
}
} catch (Exception e) { e.printStackTrace();}
bubble_srt(player_score, player_score.length);
System.out.print("Highscores:\n");
System.out.println("Scores");
System.out.println("Name\tScore");
for(i = 0; i <NUMBER_OF_HI_SCORE; i++){
System.out.print(player_name[i] + "\t" +player_score[i] + "\n");
}
}
How do I do this, without using arraylist. Just ordinary array.