How do I properly bubble sort through a text file by assigning the values to an array.
In the code below I tried to assign the values from the text file to a string while there is still something to fetch. Then I used a for loop to assign the one that I have fetch to the array.
ttry{
int i;
String ss;
FileReader fr;
fr = new FileReader (new File("F:\\players.txt"));
BufferedReader br = new BufferedReader (fr);
while ((ss = br.readLine()) != null) {
String[] sv = ss.split(" ");
String splayer_name=sv[1];
String s_player_score=sv[2];
for(int xy=0;xy<player_name.length;xy++){
player_name[xy]=splayer_name;
player_score[xy]=Integer.parseInt(s_player_score);
}
int xh=0;
bubble_srt(player_score, player_score[xh]);
System.out.println(player_name[xh] + " " +player_score[xh]);
}
}catch(Exception e){}
I get this output:
a 5
b 10
x 4
from the players.txt, which looks like this:
1 a 5
2 b 10
5 x 4
7 h 20
please help