how can i bubble sort a txt file with some text in it? and then an output txt file should be created to show how much time the bubble sort took to finish the job...
Hey there babyfrostie,
Are you having trouble reading the file, sorting the file or outputting the file? Because they are the three tasks you need to do...
oops sorry.. im ok with reading the file..
i dont know how to place the words in an array and sort the array using bubble sort. and to create an output.txt containing the time..
Since you don't know the size of the file why don't you put the strings you read into a Vector and then put the data from the Vector to an array
String line= readLine() from file
When you are done with the file use a for-loop to put the data into an array
I agree with javaAddict (To err is human, to write java code is divine - I like that!), you should read the data into a Vector<String> object. There are many ways the Bubble sort can be done, I would imagine your teacher would have given you an algorithm since he/she wants you to acknowledge the time it takes. Just remember that comparison between String objects requires the .compareTo() method.