Originally Posted by
quzah
He didn't say it couldn't be sorted while you do the copying. He said you can't sort it first. I'm not sorting it first. I'm simply copying pairs as I run across them.
Quzah.
Oh yeah thats definetly legit.
But just incase theres extra qaulifications. I made the modified version of what quzah had that will do it all in order as said in my last post.
I could post the actual code, since this guy seems to understand and care about it.. but the community may freak out if I post actual working code in an assignment post. So..
Code:
initialize the int old array
define the int maxOfNum
define three letter variables to work with the three loops
define the int new array, doesnt need values (same size as old array)
define the int static temp array, doesnt need values (same size as old array)
define the int static countOfNum, that is used to align with the temp array to see how many of each number have been copied to the new array
outer for loop looks at every element in old array, use < (element amount)
inner for loop looks at every element in temp array, but use <= (element amount) so theres 1 extra
if the index variable is equal to the last number possible in the for loop,
another inner for loop looks for a temp array element thats not used, use < (element amount)
apply the element of this loop of the temp array to the outer loop element of the old array
apply the element of the outer loop of the new array to the outer loop element of the old array
increment the countOfNum by 1
break out of the loop because you've assigned the value
break out of this loop too becaus you've assigned the value
else if the temp array value is equal to the old array value (this checks to see if the number already exists in temp array)
if the countOfNum is less than the maxOfNum
apply the element of the outer loop of the new array to the outer loop element of the old array
increment the countOfNum by 1
break out of the loop because you've assigned the value
print the new array at the end of the outer loop
It also leaves for expansion because with that it just wont copy the value from old array to new array, but since you already made new array with the same size as old array, its going to have blank spots, which will not be set. So if you used it you'd have to do what quzah said just like with his and set it to an undefined value and figure out how to get rid of that after its processed.