0

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...

thanks..

4
Contributors
4
Replies
6
Views
10 Years
Discussion Span
Last Post by PoovenM
0

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...

0

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..

1

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
ex:
String line= readLine() from file
vector.add(line)

When you are done with the file use a for-loop to put the data into an array

Votes + Comments
Cool signature! Plus good advice :)
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.