Okay some information.
C++ btw.
1. I'm reading a stream from a text file that contains random words. I know the size and it's being put into an array of strings.
2. I CANNOT load them all in and then sort them alphabetically. I have to do sort of insertion sort, i.e. put it into the array at it's correct place than move everything else along by 1 -.-.
3.
How I'm doing it currently. I have 2 identical arrays.
I then loop through finding out where the new word should be added to. Find that position. If the position is at the end of the array, I put it into that position.
If it's not then I copy into the other array, the data up to the new piece, put that in and then put in the other parts of the array.
So. Like this:
Name to be added: "Fred"
Array1:
Adam
Chris
David
George
Simon
Add:
Adam, Chris, David, to Array2.
Add Fred to Array2.
Add George, Simon to Array2.
etc. and then Array2 becomes the active array. And then if I have to insert to the middle of that array I will do the same but to Array1, etc etc until over. Currently it takes about 7 seconds to do 4158 names. Which I don't think is that fast.
Places I think I can currently optimise: The searching to find the position where it's meant to be inserted.
I cannot change the fact that it's an insertion sort and you are not allowed to put it into the array unless you put it in at the correct location (CWK rules).
Can show people my code if they want to see it. It's quite dirty lol but it works and it's faster than my friend who uses binary chop to find out where to put his.
C++ btw.
1. I'm reading a stream from a text file that contains random words. I know the size and it's being put into an array of strings.
2. I CANNOT load them all in and then sort them alphabetically. I have to do sort of insertion sort, i.e. put it into the array at it's correct place than move everything else along by 1 -.-.
3.
How I'm doing it currently. I have 2 identical arrays.
I then loop through finding out where the new word should be added to. Find that position. If the position is at the end of the array, I put it into that position.
If it's not then I copy into the other array, the data up to the new piece, put that in and then put in the other parts of the array.
So. Like this:
Name to be added: "Fred"
Array1:
Adam
Chris
David
George
Simon
Add:
Adam, Chris, David, to Array2.
Add Fred to Array2.
Add George, Simon to Array2.
etc. and then Array2 becomes the active array. And then if I have to insert to the middle of that array I will do the same but to Array1, etc etc until over. Currently it takes about 7 seconds to do 4158 names. Which I don't think is that fast.
Places I think I can currently optimise: The searching to find the position where it's meant to be inserted.
I cannot change the fact that it's an insertion sort and you are not allowed to put it into the array unless you put it in at the correct location (CWK rules).
Can show people my code if they want to see it. It's quite dirty lol but it works and it's faster than my friend who uses binary chop to find out where to put his.
Last edited: