Computer Science Canada sorting once again... |
Author: | Tallguy [ Fri Feb 13, 2009 12:55 pm ] |
Post subject: | sorting once again... |
hey guys, back to sorting and arrays FUN!!!....NOT any ways here is my problem Quote: Write a program which inputs a number of names in any order. Use a sentinel to stop
user input. Output to the screen the names in alphabetical order so that there are no duplicate names output. At the end of the program output the names of the duplicates. i have it done, except it always deletes one name, and i have no idea why...can someone help? thanks |
Author: | DemonWasp [ Fri Feb 13, 2009 1:17 pm ] | ||
Post subject: | RE:sorting once again... | ||
In your duplicate method, you're never outputting the first entry in the array. It's not deleted, it's just not shown. Add
I should also point out that your duplicates-detecting algorithm fails if you have more than two copies of a single name. For example, type in "joe" three times and it outputs "joe, joe," for duplicates. |
Author: | copthesaint [ Sat Feb 14, 2009 10:03 am ] | ||
Post subject: | RE:sorting once again... | ||
Now this works but you would have to figure out how to Eliminate 1 set of each double. Because if you put 5 of one name it will out put 25 doubles. Also you can choose if you will learn for this program. Your only hurting your self if you don't take the time to understand this. |
Author: | Tallguy [ Tue Feb 17, 2009 8:35 am ] | ||||||
Post subject: | Re: sorting once again... | ||||||
DemonWasp wrote: In your duplicate method, you're never outputting the first entry in the array. It's not deleted, it's just not shown. Add
I should also point out that your duplicates-detecting algorithm fails if you have more than two copies of a single name. For example, type in "joe" three times and it outputs "joe, joe," for duplicates. umm, okay.... so this is my duplicate thingy...
would i put
I got it to work, a bit unorthodox though, see what you think... |
Author: | DemonWasp [ Tue Feb 17, 2009 9:17 am ] | ||||
Post subject: | RE:sorting once again... | ||||
That method will also work; all you've done is shifted which element is the special case from the first element to the last element. Instead of having
You do, however, still have the problem with multiple-duplicates. If you put in the same name more than twice, it will appear in the "duplicates" list more than once, which I would assume to be incorrect behaviour. |
Author: | Tallguy [ Tue Feb 17, 2009 1:28 pm ] |
Post subject: | RE:sorting once again... |
oo, okay thanks |