Alice Community  

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

Reply
 
Thread Tools Display Modes
Sorting an array
Old
bauhaus
Guest
 
Status:
Posts: n/a
Unhappy Sorting an array - 05-17-2011, 01:28 AM

Hi! I recently started using Alice 2.2.
I'm having some trouble sorting an array. The array has 6 predefined numbers which I want to sort and print them on screen.
I've attached the world file. Any help would be very much appreciated!!
Attached Files
File Type: a2w test.a2w (6.09 MB, 15 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 05-27-2011, 09:00 PM

There are multiple ways of sorting an array. One method is the insertion sort algorithm, it is not my favorite(selection sort is my preference), but it will do.
I'm sorry I didn't make it in your world, but hopefully you can transcribe it.

Tell me if you don't understand the code.
Attached Files
File Type: a2w help.a2w (190.5 KB, 29 views)


"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."-Albert Einstein
   
Reply With Quote
Old
bauhaus
Guest
 
Status:
Posts: n/a
Default 05-30-2011, 07:49 AM

Thank you very much for your reply!
I have a problem... If the numbers in array are decimals, alice world hangs... :/
Do you have any idea?
   
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 05-30-2011, 08:34 AM

On my computer it seems fine. Try deleting the wait in the doTogetor{} and delete all the comments, they may be slowing Alice down.


"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 06:28 AM.
   
Reply With Quote
Old
bauhaus
Guest
 
Status:
Posts: n/a
Default 05-30-2011, 08:46 AM

I have deleted everything except the sorting loop.
I noticed that it works fine with some decimal number but not with every decimal number... strange...
Can you please take a look at this file? I get an "out of bounds" error with these decimals...
Attached Files
File Type: a2w help - Copy.a2w (205.1 KB, 8 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-01-2011, 05:41 PM

Computers are just fascinating aren't they. I have only one idea as to why this is happening, but even so 1-1=0 which is a plausible index to have. It is almost as if the computer is ignoring the program and doing what it wants to do

I'm sorry I just don't know.


"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-01-2011 at 06:21 PM.
   
Reply With Quote
Old
bauhaus
Guest
 
Status:
Posts: n/a
Default 06-02-2011, 12:15 AM

hahahaha... fascinating, indeed!
I know... I can't understand why is this happening?...
Thanks again for you time/interest/help!!!!
   
Reply With Quote
Improve Your Troubleshooting Techniques
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 501
Join Date: Sep 2007
Location: Austin, Texas
Default Improve Your Troubleshooting Techniques - 06-02-2011, 09:17 AM

An out-of-bounds error relates to the addressing of individual elements in an array, not their specific contents.

First, read the error message, and determine what Alice thinks the range of the array pointer should be.

Next, Try dragging a few print statements into your sort routine, and print the value of "i" at various locations.
   
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-02-2011, 02:58 PM

Okay I still don't know why the insertion sort algorithm isn't working because I just "translated" the program into C++ and it worked perfectly fine. So we are going to have to use the more difficult and slower selection sort algorithm.

Here is a world using this method...


"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-11-2011 at 06:52 PM.
   
Reply With Quote
Pay Attention
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 501
Join Date: Sep 2007
Location: Austin, Texas
Default Pay Attention - 06-02-2011, 10:19 PM

Quote:
Originally Posted by legolizard View Post
Okay I still don't know why the insertion sort algorithm isn't working because I just "translated" the program into C++ and it worked perfectly fine. So we are going to have to use the more difficult and slower selection sort algorithm.

Here is a world using this method...
What is the value of "i" when the program crashes, and what are you doing with it?
Attached Files
File Type: a2w help - Copy.a2w (221.5 KB, 1 views)
   
Reply With Quote
Reply


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 ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.