Re: quicksort

Discussion in 'C++' started by user923005, Apr 10, 2007.

  1. user923005

    user923005 Guest

    On Apr 10, 6:36 am, 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.
    user923005, Apr 10, 2007
    #1
    1. Advertising

  2. user923005

    red floyd Guest

    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.
    red floyd, Apr 10, 2007
    #2
    1. Advertising

  3. user923005 wrote:
    > On Apr 10, 6:36 am, 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.
    Gianni Mariani, Apr 10, 2007
    #3
  4. user923005

    CBFalconer Guest

    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
    CBFalconer, Apr 11, 2007
    #4
  5. user923005

    user923005 Guest

    On Apr 10, 2:27 pm, Gianni Mariani <> wrote:
    > user923005 wrote:
    > > On Apr 10, 6:36 am, 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].
    user923005, Apr 11, 2007
    #5
  6. user923005

    Guest

    On Apr 11, 1:07 am, red floyd <> 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.
    , Apr 11, 2007
    #6
  7. writes:
    > On Apr 11, 1:07 am, red floyd <> 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) <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"
    Keith Thompson, Apr 11, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sarah
    Replies:
    2
    Views:
    3,249
    Roedy Green
    Oct 23, 2003
  2. hiwa
    Replies:
    4
    Views:
    643
    Esmond Pitt
    Mar 29, 2005
  3. Exekute

    c++ and quicksort

    Exekute, Sep 27, 2003, in forum: C++
    Replies:
    6
    Views:
    9,028
    Jerry Coffin
    Sep 28, 2003
  4. David Sachs

    Re: c++ and quicksort

    David Sachs, Sep 28, 2003, in forum: C++
    Replies:
    1
    Views:
    471
    Gianni Mariani
    Sep 28, 2003
  5. Alex Vinokur
    Replies:
    0
    Views:
    978
    Alex Vinokur
    Aug 30, 2004
Loading...

Share This Page