Computer Science Canada Multiple Array Sorting (Code included) |
Author: | ntba1 [ Sat Apr 29, 2006 7:23 pm ] | ||
Post subject: | Multiple Array Sorting (Code included) | ||
Hey guys just finishing off an assignment I have but I have one last critical part of my program before I can finish it and be able to clean the code up and make the interface look nice. I have a lottery sales program where people enter their Class number, Tickets sold and number of students. The last part of this assignment involves sorting the classes from most tickets sold to least tickets sold. That's fine and dandy, just sort the array but how would I have the other two array's line up to that one(Since Homeroom, TicketsSold and Students are all separate arrays). Here's the code (Yes I know it could be cleaner and if your wondering what the goto vars are for it's me trying to fake goto, plus I just started with Turing, I bet there is a MUCH easier way to do what I did) Remember I am using Classic Turing 6.5 and I cannot do anything about it my teacher insists we use it.
Thanks and I hope I didn't confuse you guys with my code ![]() PS. Feel free to reccomend any other changes I can do to make my code better! |
Author: | do_pete [ Sat Apr 29, 2006 7:46 pm ] |
Post subject: | |
You should use record instead of having 4 arrays. Also setscreen ("graphics:vga") doesn't do anything because Turing always starts in graphics mode. |
Author: | ntba1 [ Sat Apr 29, 2006 7:58 pm ] |
Post subject: | |
Well I was praying that I wouldn't have to do something like rewrite everything after spending the whole day writing this. Is it possible to sort the arrays some way without having to do it with records? ![]() |
Author: | do_pete [ Sat Apr 29, 2006 8:06 pm ] |
Post subject: | |
You don't need records, I'm just saying it would be better with them.[/i] |
Author: | ntba1 [ Sat Apr 29, 2006 8:16 pm ] |
Post subject: | |
OK that's a relief but how would I go about implementing this sort then? I have no clue where to start from. Perhaps you can write some Pseudocode showing me how to write this? Thanks again ![]() |
Author: | Cervantes [ Sat Apr 29, 2006 8:18 pm ] | ||
Post subject: | |||
If you refuse to switch to records (which would by far be easiest, easier than what I'm about to suggest), just modify the other arrays in parallel to the one you're sorting by.
|
Author: | ntba1 [ Sat Apr 29, 2006 9:29 pm ] |
Post subject: | |
Thanks a bunch! I've learned my lesson time to go read up on records ![]() |
Author: | MysticVegeta [ Sun Apr 30, 2006 10:20 am ] | ||
Post subject: | |||
Heh, well if you dont want to code the whole thing seeing that you have spent a lot of time doing coding, I will tell you how to do it without records, Cervantes' code is pretty useful too its more organized and easier to understand, but look whats going on in the code that I am posting. You see, "arr" array carries random numbers, "arr2" carries a string from "1" to "5", "arr3" carries numbers from 1 to 5, now I use the same old sorting algorithm, but I create 2 more temp variables, now whenever the "if" condition is met, not only do I change the values of the "arr" array, I also change the values of "arr2" and "arr3". Thats the key. The first 5 lines are the original #s and the other 5 lines after the line break show how the first column is sorted and the values of the second and third column are organized according to it.
|