Re: selection sort program
Re: selection sort program
Sounds like homework of some sort. Have you tried writing a selection sort algorithm yourself?
Re: selection sort program
Why selection sort?
You are going to have to read all the lines from the text file, sort them, then write them all back out. If the file is just a list of names, with one name per line, then this is a really simple task....until you decide to use some kind of custom sorting algorithm. That step alone will increase the level of difficulty from about three lines to many.
In any case, you will be sorting an array of strings, so if you have to make your own sorting routine, make one that sorts arrays of strings.
Re: selection sort program
Read here. You can even find sample code (written in C++ though)
http://www.codecodex.com/wiki/index....Selection_sort
Re: selection sort program
Quote:
Originally Posted by Shaggy Hiker
Why selection sort?
Because it's a homework assignment and the teacher specifies to use selection sort.... :)
Re: selection sort program
That's what most questions are, but I thought I'd lead off with a question.
I've wondered about these homework assignments before, and I will wonder about them again. I can understand the idea that you teach someone how a sort routine works, but why choose one over any other? I guess I can understand why Shell sort and qSort aren't taught, since they are nearly impossible to understand, but why selection sort?
Re: selection sort program
http://en.wikipedia.org/wiki/Selection_sort
Take a shot at it and then post your code if you need help.