Chat on IRC |
c program sorting function URGENT!
Posted by mamamia [send private reply] at September 17, 2002, 09:15:56 AM
I have to sort a list of arrays that looks like this (except that its huge and I do not know how many records there is, and looks something like this:
a b c 1 3 49586 3 6 15496 1 3 76459 4 6 29384 2 4 29292 etc. I have to sort this list by "c" and then separate it into lists like this (by "b"s, and also sorted ny "c"): a b c 1 3 49586 1 3 76459 a b c 3 6 15496 4 6 29384 a b c 2 4 29292 List is passed as an array from another function (as pointer). Does anybody know how to do this? Thank you
Posted by DragonWolf [send private reply] at September 17, 2002, 09:54:50 AM
I haven't thought this through fully, but I think bubble sorting in the reverse order will produce it all in the correct sequence (i.e. if you want it sorted by a then b then c, then try sorting by c then b then a using a bubble sort)
This method won't work with some other types of sort.
Posted by DragonWolf [send private reply] at September 17, 2002, 09:56:34 AM
If you want them in seperate lists then there should be no need to sort them, simply go through the list placing them into the appropiate list for that number. (Bucket Sort)
Posted by mamamia [send private reply] at September 17, 2002, 10:17:11 AM
Thank you a lot,
but is there a possibility that somebody can tell me how to do it. I mean, to put them in separate lists and then sort them by "c". Also I am not sure how can I do it by passing array (list) as a pointer that is read in the previous function? Pleeeeease let me know, it's urgent Thanks again
Posted by diegoeskryptic [send private reply] at September 17, 2002, 12:56:32 PM
urgent?... they dont do homework here in TPU... i thought there was a rule on how mayn lines of code u can put at a time.....
Posted by Psion [send private reply] at September 17, 2002, 03:32:41 PM
mamamia, if you don't know how to code such a basic thing, then get help from your instructor. That's why he/she is there.
Posted by gian [send private reply] at September 18, 2002, 03:13:23 AM
Mamamia, Psion said mamamia!
Posted by DragonWolf [send private reply] at September 18, 2002, 05:04:19 AM
If you look up bubble sort and bucket sort on google.com you should find some code, explaination and help with those sorts of sorts. (pun not intended)
That should give you plenty of code and explaination to get you on your way.
Posted by Psion [send private reply] at September 18, 2002, 06:35:23 AM
Incidentally, you should never use bubble sort. Ever.
Posted by DragonWolf [send private reply] at September 18, 2002, 07:58:50 AM
why not?
quicksort would not work with this method ^^
Posted by unknown_lamer [send private reply] at September 18, 2002, 08:12:14 AM
We all know that BogoSort is the best sorting algorithm!
Posted by DragonWolf [send private reply] at September 18, 2002, 08:59:19 AM
wtf is bogosort?
Posted by DragonWolf [send private reply] at September 18, 2002, 09:01:13 AM
lol just looked it up in google..
now that is about as stupid an algorithm as they get ^^
Posted by unknown_lamer [send private reply] at September 18, 2002, 09:15:57 AM
BogoSort is the BEST algorithm ever! It can sort faster than all the others!
Posted by DragonWolf [send private reply] at September 18, 2002, 09:18:13 AM
Psion: I doubt he has more than 2000 records, plus its the easiest one to implement that is stable.
Posted by DragonWolf [send private reply] at September 18, 2002, 09:23:37 AM
It CAN sort faster than all the others ^^
Whether it WILL sort faster than all the others is another question ^^
Posted by unknown_lamer [send private reply] at September 19, 2002, 08:19:48 AM
Ah, so you finally got the joke! Give me my quantum computer and universe creator/destroyer!
Posted by RedX [send private reply] at September 19, 2002, 01:13:43 PM
U know you can't build or destroy universes without proper permits. God did it once and is still in prison for that. (Doesn't this answer the question why God <replace by name of the supernatural creature U happen to be worshipping> hasn't done anything about the evil in the world?)
Posted by mop [send private reply] at September 19, 2002, 06:00:20 PM
Before they put him in prison, he wanted to get revenge. So he made us and they didn't take it as a threat at the time. But look at us now! Mwahahaah!
Posted by RedX [send private reply] at September 20, 2002, 02:28:46 PM
we were put here to lead the normals (a.k.a. the ignorant, the nono, the newbie, ...) to the (monitor)light.
Register as a new user | ||||||||||||||||||||||