Well, since I don't have 100% C/C++ programming knowledge, I am not going to
argue with either of you two (Mike/Kender)... all I know is that my Skills
list sorts and his Helps sort ok by using the "Linked List" that you both
are saying won't work...

Here is my question:

Once you read the file contents into memory, doesn't it technically become
an array??? If it DOES, then you can sort it directly.

-V

----- Original Message ----- 
From: "Mike Barton" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, January 28, 2004 6:32 PM
Subject: Re: Qsort


> Front end function for qsorting linked lists.. written on my way out the
> door, so I wouldn't use it on something that might screw up too bad:
>
> /* merc.h */
> #define NEXTPTR(list) ((char *)&(list->next) - (char *)list)
> void *list_sort(void *list, int nextpos, int(*compar)(const void *,
>   const void *));
>
> /* some .c file */
> void *list_sort(void *list, int nextpos, int(*compar)(const void *,
>   const void *))
> {
>   int count = 0, i = 0;
>   unsigned char *ptr = list;
>   unsigned char **array;
>   for (; ptr != NULL; count++)
>     ptr = (void *)*(long *)(ptr+nextpos);
>   array = malloc(sizeof(void *)*count);
>   ptr = list;
>   for (; ptr != NULL; ptr = (void *)*(long *)(ptr+nextpos))
>     array[i++] = ptr;
>   qsort(array, count, sizeof(unsigned char *), compar);
>   list = NULL;
>   for (count--;count >= 0; count--)
>   {
>     (void *)*(long *)(array[count]+nextpos) = list;
>     list = array[count];
>   }
>   free(array);
>   return list;
> }
>
> /* to use it */
> list = list_sort(list, NEXTPTR(list), comparison_function);
>
> --Palrich.
>
> On Wed, 2004-01-28 at 15:43, Chad Simmons wrote:
> > --- Valnir <[EMAIL PROTECTED]> wrote:
> > > if you look at his original call to Qsort he IS passing it a count.
> > >
> > > he is passing it "i" which is counted during a for loop prior to the
Qsort
> > > call.
> > >
> >
> >
> > Yes, he's passing a count. What he is NOT passing is an array. Qsort
doesn't
> > operate on linked lists. If it did you wouldn't need to pass a count,
cause it
> > would just stop when it got to the NULL record on the end. The point of
> > contention has been that (as per the man page) qsort takes the address
to the
> > first element in an array, the count of elements in the array, and a
pointer to
> > a comparison function.
> >
> > ~Kender
>
>
>
> -- 
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom
>


Reply via email to