When the program crashes the value of "i" is 0 so when it says i-0(-1) which does not exist so it crashes, but oddly the i stays the same without decimals so I don't know , but selection sort does work.
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."-Albert Einstein
Last edited by legolizard; 06-02-2011 at 10:28 PM.
A friend of a friend of mine emailed me yesterday his "solution" and as I can see it works without crashes/errors...
I've attached the world if you want to check it...
So the problem I guess is in the compound statement && because in that world he said
if(i>0){
if(temp<array[i-1])
{
//Swap
}
else{
//end loop
}
else
{
//end loop
}
Where I said
if(i>0&&temp<array[i-1])
{
//Blahblah
}
So okay use that world. Glad you figured it out.
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."-Albert Einstein
First off when I wrote the program in C++ I didn't do the same thing, in fact it was entirely different(as for why I did this I don't have an answer).
My fist mistake was in how I initialized i and instead if making it equal to index-1 I set it to index. My second mistake was that within the while loop I forgot to had an if statement that checked to see if i was equal to -1(this after decrementing) and if it was then a[0] would need to be changed to itemToInsert.
Here is my final world
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."-Albert Einstein
Last edited by legolizard; 06-03-2011 at 07:47 PM.
I was wondering if I could goad one of you into seeing the errors. Years of programming have taught me the value of a well placed print statement to view the error of my logic.
Of course, if you actually want to watch it happen in Alice, it takes a little more work, and you have to slow it down a bit. (MP4 in zip)