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

Recommended Answers

All 4 Replies

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

commented: Cool signature! Plus good advice :) +2

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.