Originally Posted by
Mr.777
for(int a = 0; a < sortedStack; a++)
{
tempStack[stackCount] = stack[a];
stackCount++;
}
Why it's not a<sortedStack-1 ?? Just a question or a hint as i don't know much about what you trying to do.
Ah that is an error, thanks!
I'm still having the same problem though unfortunately.
Originally Posted by
Mr.777
What is prevIndex???
Junk code from when I counted the next position as the previous index + 1. I'll remove that.
Originally Posted by
Mr.777
for(int i = 0; i < (size - 1); i++)
Why your loop always start from 0 and iterate for "size" iterations?
The maximum amount of flips required is never higher than the array size, I think.
Originally Posted by
Mr.777
I just posted the status of all variables, may be this could help you out. And what are the logics, where i have asked you about in my post.
That's very useful, much appreciated!
The basic logic behind the system:
*Find the largest integer that has an index higher than "sortedStack", which are already in the correct position
*If this integer is already in the correct position, no rotations required, just increase sortedStack by one
*Else if this integer is in the last position in the array, rotate from the position after sortedStack to from a situation like above
*Otherwise rotate the highest integer so it is in the last position in the array and then rotate at the position after sortedStack so it becomes sorted
*Fill a second temporary array with the new array positioning using the shown for loop logics
*Make the primary array equal to this temporary array
*Increase sortedStack by one as we now have another sorted number
Hope this helps. Thank you very much for your help so far