|
Page 1 of 1
|
[ 6 posts ] |
|
Author |
Message |
Simon1
Rookie
Joined: Thu Jul 19, 2012 11:59 am Posts: 10
|
 Sorting Numbers
Hey, I need help for an assignment. The Assignment: For this assignment you will design and implement a program that will sort a set of audio tones into low to high order. Your program will 1) generate a set of 8 random notes, 2) display and play them through the speaker, 3) sort them into low-to-high order, 4) display and play them in this sorted order, and 5) keep on the display screen the original and sorted order of the notes, and keep playing the tones in original order, and then in the sorted order until the user pushes a button, at which point the program exits.I am stuck on number 3. I do not know how to get the program to sort through random numbers and figure out which are higher or lower. Any help would be great. Thanks P.S My code so far is:  |  |  |  | Code: task main() { int rand0 = random[1000]; int rand1 = random[1000]; int rand2 = random[1000]; int rand3 = random[1000]; int rand4 = random[1000]; int rand5 = random[1000]; int rand6 = random[1000]; int rand7 = random[1000];
PlayTone(rand0,10); nxtDisplayTextLine(0,"Tone: %d", rand0); wait1Msec(1000); PlayTone(rand1,10); nxtDisplayTextLine(1,"Tone: %d", rand1); wait1Msec(1000); PlayTone(rand2,10); nxtDisplayTextLine(2,"Tone: %d", rand2); wait1Msec(1000); PlayTone(rand3,10); nxtDisplayTextLine(3,"Tone: %d", rand3); wait1Msec(1000); PlayTone(rand4,10); nxtDisplayTextLine(4,"Tone: %d", rand4); wait1Msec(1000); PlayTone(rand5,10); nxtDisplayTextLine(5,"Tone: %d", rand5); wait1Msec(1000); PlayTone(rand6,10); nxtDisplayTextLine(6,"Tone: %d", rand6); wait1Msec(1000); PlayTone(rand7,10); nxtDisplayTextLine(7,"Tone: %d", rand7); wait1Msec(5000);
} |  |  |  |  |
|
Thu Jul 19, 2012 12:02 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: Sorting Numbers
There are many sorting algorithms. If you search the Internet, you will get many articles on various algorithms. You can start by reading some of these articles to learn various sorting algorithms and their performance. For example: http://en.wikipedia.org/wiki/Sorting_algorithm
|
Thu Jul 19, 2012 12:11 pm |
|
 |
Simon1
Rookie
Joined: Thu Jul 19, 2012 11:59 am Posts: 10
|
 Re: Sorting Numbers
Do you have any code examples?
|
Thu Jul 19, 2012 12:33 pm |
|
 |
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1523
|
 Re: Sorting Numbers
No, I don't have any sorting sample code for RobotC. For Windows platform, I generally called the C-Runtime library qsort unless I have specific needs then I may implement my own sorting code. Again, if you search the Internet, I am sure you will find sample code for various sorting algorithms.
|
Thu Jul 19, 2012 12:44 pm |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: Sorting Numbers
Didn't take me long to find a C++ example with some simple arrays and about 2 minutes to make it work in ROBOTC. Look for various sorting algorithm examples: - Insertion sort
- Bubble sort
- Quick sort
It doesn't really matter which one you pick. I doubt it'll make much difference with the small amount of data you're using  - Xander
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Thu Jul 19, 2012 2:42 pm |
|
 |
mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3654 Location: Rotterdam, The Netherlands
|
 Re: Sorting Numbers
_________________| Professional Conduit of Reasonableness| (Title bestowed upon on the 8th day of November, 2013) | My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
Sat Jul 21, 2012 1:56 pm |
|
|
|
Page 1 of 1
|
[ 6 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 2 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|