Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Old
legolizard
Senior Member
 
legolizard's Avatar
 
Status: Offline
Posts: 242
Join Date: Jan 2011
Location: Aboard the Hyperion escaping the zerg.
Default 06-02-2011, 10:25 PM

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.
   
Reply With Quote
Old
bauhaus
Guest
 
Status:
Posts: n/a
Default 06-03-2011, 10:16 AM

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...
Attached Files
File Type: a2w help - final.a2w (217.9 KB, 9 views)
   
Reply With Quote
Old
legolizard
Senior Member
 
legolizard's Avatar
 
Status: Offline
Posts: 242
Join Date: Jan 2011
Location: Aboard the Hyperion escaping the zerg.
Default 06-03-2011, 10:53 AM

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
   
Reply With Quote
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 501
Join Date: Sep 2007
Location: Austin, Texas
Default 06-03-2011, 11:13 AM

actually, neither one of you figured it out.
   
Reply With Quote
Old
legolizard
Senior Member
 
legolizard's Avatar
 
Status: Offline
Posts: 242
Join Date: Jan 2011
Location: Aboard the Hyperion escaping the zerg.
Default 06-03-2011, 12:45 PM

I got it Mr.Moke.

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
Attached Files
File Type: a2w Solved.a2w (198.5 KB, 9 views)


"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.
   
Reply With Quote
Yep!
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 501
Join Date: Sep 2007
Location: Austin, Texas
Default Yep! - 06-03-2011, 04: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)
Attached Files
File Type: zip SortVideo.zip (228.3 KB, 9 views)

Last edited by MrMoke; 06-04-2011 at 06:17 PM.
   
Reply With Quote
Old
bauhaus
Guest
 
Status:
Posts: n/a
Default 06-05-2011, 09:10 PM

Thank you both for your help!!
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2023, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.