Sorting records using sort()

From: Elijah Bailey (geomrock_at_hotmail.com)
Date: 12/31/03


Date: 31 Dec 2003 08:12:42 -0500

I want to sort a set of records using STL's sort() function,
but dont see an easy way to do it.

I have a

char *data;

which has size mn bytes where m is size of the record and
n is the number of records. Both these numbers are known
only dynamically. I have a function less_than that can compare
two records of size m given the pointers to the two records.

Is there an easy way to call STL sort() on this data and sort it.
The data is big and I do NOT want to allocate a list of pointers
of size n or anything linear in size. Assume that except the data,
we do not have much space...

I thought of tricking sort() using a dummy Record class that is
templated using the size of the record...But since m can change
dynamically this doesnt work.

Thanks in advance for your comments,
--Elijah

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated. First time posters: Do this! ]



Relevant Pages

  • Re: polymorphic structs with "methods"
    ... without checking some sort of struct "type" member and then using a ... switch statement to call the appropriate function for that type. ... range from "hideous worst practice ever" to "yep people do that sort ... the tedium of initializing each instance's pointers. ...
    (comp.lang.c)
  • Re: Writing a program to sort numbers - HELP!
    ... You may not have a choice but strtol is preferred to atoi and fgets is ... Then we using a sort function to sort the ... >int main ... probably meant *u and *v to dereference the pointers you received from ...
    (comp.lang.c.moderated)
  • Re: Windows Error at run-time...
    ... > My problem is that I am not used to pointers and my little app ... > always crashes at run-time...access violation of some sort. ... my app doesn't even create an application window but crashes ...
    (comp.lang.cpp)
  • Re: Using a link list over an array.
    ... compile (p->data is a void *) so you have not shown us some key ... You can't use it to sort a list of ints where the int is ... You can use it to sort a list of pointers to any type. ...
    (comp.lang.c)
  • Re: Looking for advice on how to deal with array of structs
    ... and filtering out bits of the line. ... an array of structs, that will hold lines that match, sort them on the ... A somewhat simpler data structure is an array pointers, ...
    (comp.lang.c)