quicksort

A

aparnakakkar2003

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

Chris Dollin

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
 
U

user923005

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

You want for C++ questions (*not* 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 from the headers.
 
R

red floyd

user923005 said:
You want for C++ questions (*not* 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.
 
G

Gianni Mariani

user923005 said:
You want for C++ questions (*not* 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 from the headers.

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

CBFalconer

Gianni said:
user923005 wrote:
.... snip ...

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
 
U

user923005

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].
 
A

aparnakakkar2003

user923005 said:
You want for C++ questions (*not* 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.
 
K

Keith Thompson

user923005 said:
You want for C++ questions (*not* 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top