Computer Science Canada I need help in making my sorting algorithim idea work |
Author: | Nyrd [ Wed Oct 13, 2004 8:58 pm ] | ||
Post subject: | I need help in making my sorting algorithim idea work | ||
I'm making a sorting algorithim that compares a randomly generated number to a group of numbers that are in ascending order, and then puts the number into an array full of 0's. I got it to organize numbers, but the problem is that it only works if a group of numbers is all there. (12234 won't work, but 52314 does) I'd apprieciate it someone could help, caus i just can't figure it out
here's my code sofar to help you help me |
Author: | Delos [ Thu Oct 14, 2004 5:58 pm ] |
Post subject: | |
Let me get this straight? This code is supposed to take x numbers, sort them, and return x numbers? If that's the case then you've got quite a problem...since you're only considering one instance of each number [0..x] at most x numbers will be returned, but on average less than x numbers will be returned (due to repititions, resulting in several numbers only counting as one number) and if not all numbers in the range are given, a bunch of zeros will be returned... Ok, if you're going to stay with your current implementation, add another array to count the occurences of each number in the range [0, x] So for the numbers: 0, 1, 5, 7, 4, 4, 6, 2, 3 The sorted list will be: 0, 1, 2, 3, 4, 5, 6, 7 The counted list will be: 1, 1, 1, 1, 2, 1, 1, 1 And the returned list will be: 0, 1, 2, 3, 4, 4, 5, 6, 7 Get it? Got it? Good. |
Author: | Nyrd [ Sun Oct 17, 2004 7:24 pm ] | ||
Post subject: | |||
would the code for the array mentioned above be something like ..
|