Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > quicksort

Reply
Thread Tools

quicksort

 
 
aparnakakkar2003@gmail.com
Guest
Posts: n/a
 
      04-10-2007
hello
can any one tell me how i can create program to sort string
list(standard template library) using quicksort.

 
Reply With Quote
 
 
 
 
Chris Dollin
Guest
Posts: n/a
 
      04-10-2007
wrote:

> hello
> can any one tell me how i can create program to sort string
> list(standard template library) using quicksort.


"standard template library" is C++, not C; perhaps you were reading
the map upside-down?

quicksort isn't C, either [the library function `qsort` needn't be
implemented with quicksort].

If you were to sort an array of strings in C, using `qsort`, you'd
write a comparison function that used the signature `qsort` expects:

int(*compar)(const void *, const void *)

remembering that the `const void *`s will be pointing to strings and
hence will need casting to `char **` and need a dereference in the
likely call to `strcmp`.

--
Yes, Virginia, there is a second Jena user conference: Palo Alto, Sep 2007.
"Life is full of mysteries. Consider this one of them." Sinclair, /Babylon 5/

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

 
Reply With Quote
 
 
 
 
user923005
Guest
Posts: n/a
 
      04-10-2007
On Apr 10, 6:36 am, aparnakakkar2...@gmail.com wrote:
> hello
> can any one tell me how i can create program to sort string
> list(standard template library) using quicksort.


You want news:comp.lang.c++ for C++ questions (*not* news:comp.lang.c,
which is strictly for the C language).

I would recommend looking up vector and sort in ISO/IEC 14882:1998(E)
which is the C++ standard.

Consider a vector v populated with class string. If we want to sort
with a French locale, it is as easy as:
std::sort(v.begin(), v.end(), loc);

You could possibly use cstdlib and qsort with an array of strings, and
write your own string compare function.
But it's not the C++ way of doing things. It reminds me of teaching C
to Fortran programmers. You often end up with "C-Tran".

Sorry about not setting follow-ups correctly. Hopefully, any
responders will trim news:comp.lang.c from the headers.

 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      04-10-2007
user923005 wrote:

> You want news:comp.lang.c++ for C++ questions (*not* news:comp.lang.c,
> which is strictly for the C language).
>
> I would recommend looking up vector and sort in ISO/IEC 14882:1998(E)
> which is the C++ standard.
>


[PEDANTIC]

Current rev of the standard is ISO/IEC 14882:2003.
 
Reply With Quote
 
Gianni Mariani
Guest
Posts: n/a
 
      04-10-2007
user923005 wrote:
> On Apr 10, 6:36 am, aparnakakkar2...@gmail.com wrote:
>
>>hello
>>can any one tell me how i can create program to sort string
>>list(standard template library) using quicksort.

>
>
> You want news:comp.lang.c++ for C++ questions (*not* news:comp.lang.c,
> which is strictly for the C language).
>
> I would recommend looking up vector and sort in ISO/IEC 14882:1998(E)
> which is the C++ standard.
>
> Consider a vector v populated with class string. If we want to sort
> with a French locale, it is as easy as:
> std::sort(v.begin(), v.end(), loc);
>
> You could possibly use cstdlib and qsort with an array of strings, and
> write your own string compare function.
> But it's not the C++ way of doing things. It reminds me of teaching C
> to Fortran programmers. You often end up with "C-Tran".
>
> Sorry about not setting follow-ups correctly. Hopefully, any
> responders will trim news:comp.lang.c from the headers.
>


std::list has a sort method that more than likely uses quicksort.

 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      04-11-2007
Gianni Mariani wrote:
> user923005 wrote:
>

.... snip ...
>>
>> Sorry about not setting follow-ups correctly. Hopefully, any
>> responders will trim news:comp.lang.c from the headers.

>
> std::list has a sort method that more than likely uses quicksort.


Not on c.l.c. Follow-ups set (again).

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
user923005
Guest
Posts: n/a
 
      04-11-2007
On Apr 10, 2:27 pm, Gianni Mariani <gi3nos...@mariani.ws> wrote:
> user923005 wrote:
> > On Apr 10, 6:36 am, aparnakakkar2...@gmail.com wrote:

>
> >>hello
> >>can any one tell me how i can create program to sort string
> >>list(standard template library) using quicksort.

>
> > You want news:comp.lang.c++ for C++ questions (*not* news:comp.lang.c,
> > which is strictly for the C language).

>
> > I would recommend looking up vector and sort in ISO/IEC 14882:1998(E)
> > which is the C++ standard.

>
> > Consider a vector v populated with class string. If we want to sort
> > with a French locale, it is as easy as:
> > std::sort(v.begin(), v.end(), loc);

>
> > You could possibly use cstdlib and qsort with an array of strings, and
> > write your own string compare function.
> > But it's not the C++ way of doing things. It reminds me of teaching C
> > to Fortran programmers. You often end up with "C-Tran".

>
> > Sorry about not setting follow-ups correctly. Hopefully, any
> > responders will trim news:comp.lang.c from the headers.

>
> std::list has a sort method that more than likely uses quicksort


If you mean the quicksort algorithm, then std::list needs some
attention (read:"it's broken").

The STL's sort algorithm is introspective sort (unless you request a
stable sort). That algorithm is clearly superior to quicksort.

If (on the other hand) you mean it calls qsort(), then that might not
be so bad. Modern C libraries tend to implement the introspective
sort algorithm, which does not go quadratic with perverse inputs like
the quicksort algorithm does because it detects recursion depth and
switches to heapsort in the perverse cases [which provably cannot be
removed for all input sets].

 
Reply With Quote
 
aparnakakkar2003@gmail.com
Guest
Posts: n/a
 
      04-11-2007
On Apr 11, 1:07 am, red floyd <no.s...@here.dude> wrote:
> user923005 wrote:
> > You want news:comp.lang.c++ for C++ questions (*not* news:comp.lang.c,
> > which is strictly for the C language).

>
> > I would recommend looking up vector and sort in ISO/IEC 14882:1998(E)
> > which is the C++ standard.

>
> [PEDANTIC]
>
> Current rev of the standard is ISO/IEC 14882:2003.

thnks for ur reply
Can u tell me if its possible with String list as argument of the
function.

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      04-11-2007
writes:
> On Apr 11, 1:07 am, red floyd <no.s...@here.dude> wrote:
>> user923005 wrote:
>> > You want news:comp.lang.c++ for C++ questions (*not* news:comp.lang.c,
>> > which is strictly for the C language).

>>
>> > I would recommend looking up vector and sort in ISO/IEC 14882:1998(E)
>> > which is the C++ standard.

>>
>> [PEDANTIC]
>>
>> Current rev of the standard is ISO/IEC 14882:2003.

> thnks for ur reply
> Can u tell me if its possible with String list as argument of the
> function.


It's "you", not "u". It's "your", not "ur". It's "Thanks", not
"thnks".

And it's comp.lang.c++, not comp.lang.c. Followups redirected.

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gosling's quicksort freezes hiwa Java 4 03-29-2005 08:59 AM
Bentley-Sedgewick ternary QuickSort: C++/C implementation? Alex Vinokur C++ 0 08-30-2004 05:45 AM
Tabelle mit quicksort alphabetisch sortieren Sarah Java 2 10-23-2003 08:18 PM
c++ and quicksort Exekute C++ 6 09-28-2003 09:28 AM
Re: c++ and quicksort David Sachs C++ 1 09-28-2003 02:13 AM



Advertisments