how do i sort reords from Z-A? (in turbo C)

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2005
Posts: 15,629
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1496
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: how do i sort reords from Z-A? (in turbo C)

 
0
  #11
Sep 19th, 2005
Oh! your right Dave -- because subtracting a minus is really addition. I knew that, just checking if you did too :cheesy: :o
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,629
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1496
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: how do i sort reords from Z-A? (in turbo C)

 
0
  #12
Sep 19th, 2005
Originally Posted by Dave Sinkula
  1. int bar(const void *a, const void *b)
  2. {
  3. const int *x = a, *y = b;
  4. return (*x > *y) - (*x < *y);
  5. }
That will not compile with either VC++ 6.0 or Dev-C++. Requires cast like this

  1. int bar(const void *a, const void *b)
  2. {
  3. const int *x = (int*)a, *y = (int*)b;
  4. return (*x > *y) - (*x < *y);
  5. }

but otherwise an interesting algorithm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,459
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 252
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: how do i sort reords from Z-A? (in turbo C)

 
0
  #13
Sep 19th, 2005
Avoid compiling C code in a C++ compiler. (Or else save the file with a .c extension instead of .cpp!)

[edit]
but otherwise an interesting algorithm.
Yeah, I've been trying to Google the thing about 'no branches' or 'no instruction flush' or whatever it was -- something potentially beneficial to remember so that I could Google it again one day.

[edit=2]Here's another integer compare function that Narue might enjoy.
  1. int baz(const void *a, const void *b)
  2. {
  3. const int *x = a, *y = b;
  4. return (*x < *y) ? -1 : (*x > *y);
  5. }

[edit=3]And note that in all my posts to this thread, the comparison function when used with qsort would sort in increasing order -- rather than the OP's requested decreasing order.
Last edited by Dave Sinkula; Sep 19th, 2005 at 5:09 pm. Reason: Noting when I was finished editing.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,847
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 753
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: how do i sort reords from Z-A? (in turbo C)

 
0
  #14
Sep 19th, 2005
>So why bother in that comparison function I posted ?
Because pointers to void can be funny beasties. I like to make sure that everything matches up before the function call on the off chance that I miss a subtle issue. That's actually a throwback from when I didn't fully understand pointers and wrote code to protect myself from my own ignorance, but at the very least it proves that I know what types strcmp expects.

>That will not compile with either VC++ 6.0 or Dev-C++. Requires cast like this
Try Turbo C, at least that way you won't accidentally compile as C++.
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC