Stable Sort Method - Where Can I Get One?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Brown

    #1

    Stable Sort Method - Where Can I Get One?

    Hi,

    I need a stable sort and can find none in the MS libraries.
    Is there a simple one available on the internet? It needed
    for sorting various lists of maybe 1K elements - mostly
    ListView columns.

    I took an algorithms course many years ago and learned
    to really hate writing sort routines or I would just write one.

    Googles lists many tutorials and conversations but no
    methods.

    Thanks,
    Gary


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Stable Sort Method - Where Can I Get One?

    Gary,

    Why not use the static Sort method on the Array class, or the Sort
    method on the List<Tclass? You can easily store your items in these
    structures and then use a custom comparer to compare instances of the items.
    Then, the Sort method will do the rest for you.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Gary Brown" <garyjbrown@cha rter.netwrote in message
    news:ef21zzS2HH A.4680@TK2MSFTN GP03.phx.gbl...
    Hi,
    >
    I need a stable sort and can find none in the MS libraries.
    Is there a simple one available on the internet? It needed
    for sorting various lists of maybe 1K elements - mostly
    ListView columns.
    >
    I took an algorithms course many years ago and learned
    to really hate writing sort routines or I would just write one.
    >
    Googles lists many tutorials and conversations but no
    methods.
    >
    Thanks,
    Gary
    >
    >

    Comment

    • Doug Forster

      #3
      Re: Stable Sort Method - Where Can I Get One?

      Hey Nicholas,

      AFAIK these sorts are *not* stable. Definitely the List<Tone isn't, I just
      did a quick test.

      Cheers
      Doug Forster

      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote in
      message news:OTMjb7S2HH A.4880@TK2MSFTN GP03.phx.gbl...
      Gary,
      >
      Why not use the static Sort method on the Array class, or the Sort
      method on the List<Tclass? You can easily store your items in these
      structures and then use a custom comparer to compare instances of the
      items. Then, the Sort method will do the rest for you.
      >
      >
      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m
      >
      "Gary Brown" <garyjbrown@cha rter.netwrote in message
      news:ef21zzS2HH A.4680@TK2MSFTN GP03.phx.gbl...
      >Hi,
      >>
      >I need a stable sort and can find none in the MS libraries.
      >Is there a simple one available on the internet? It needed
      >for sorting various lists of maybe 1K elements - mostly
      >ListView columns.
      >>
      >I took an algorithms course many years ago and learned
      >to really hate writing sort routines or I would just write one.
      >>
      >Googles lists many tutorials and conversations but no
      >methods.
      >>
      >Thanks,
      >Gary
      >>
      >>
      >
      >

      Comment

      • Brette.Net

        #4
        Re: Stable Sort Method - Where Can I Get One?

        On Aug 7, 3:36 pm, "Doug Forster" <nobody@nowhere ,comwrote:
        Hey Nicholas,
        >
        AFAIK these sorts are *not* stable. Definitely the List<Tone isn't, I just
        did a quick test.
        >
        Cheers
        Doug Forster
        >
        "Nicholas Paldino [.NET/C# MVP]" <m...@spam.guar d.caspershouse. comwrote in
        messagenews:OTM jb7S2HHA.4880@T K2MSFTNGP03.phx .gbl...
        >
        >
        >
        Gary,
        >
        Why not use the static Sort method on the Array class, or the Sort
        method on the List<Tclass? You can easily store your items in these
        structures and then use a custom comparer to compare instances of the
        items. Then, the Sort method will do the rest for you.
        >
        --
        - Nicholas Paldino [.NET/C# MVP]
        - m...@spam.guard .caspershouse.c om
        >
        "Gary Brown" <garyjbr...@cha rter.netwrote in message
        news:ef21zzS2HH A.4680@TK2MSFTN GP03.phx.gbl...
        Hi,
        >
        I need a stable sort and can find none in the MS libraries.
        Is there a simple one available on the internet? It needed
        for sorting various lists of maybe 1K elements - mostly
        ListView columns.
        >
        I took an algorithms course many years ago and learned
        to really hate writing sort routines or I would just write one.
        >
        Googles lists many tutorials and conversations but no
        methods.
        >
        Thanks,
        Gary- Hide quoted text -
        >
        - Show quoted text -
        Can you please define stable?

        Comment

        • Nicholas Paldino [.NET/C# MVP]

          #5
          Re: Stable Sort Method - Where Can I Get One?

          Doug,

          Care to say what makes them not stable? I've definitely never had an
          erroneous result using them.

          --
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard. caspershouse.co m

          "Doug Forster" <nobody@nowhere ,comwrote in message
          news:ue37vKT2HH A.4880@TK2MSFTN GP03.phx.gbl...
          Hey Nicholas,
          >
          AFAIK these sorts are *not* stable. Definitely the List<Tone isn't, I
          just did a quick test.
          >
          Cheers
          Doug Forster
          >
          "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote
          in message news:OTMjb7S2HH A.4880@TK2MSFTN GP03.phx.gbl...
          >Gary,
          >>
          > Why not use the static Sort method on the Array class, or the Sort
          >method on the List<Tclass? You can easily store your items in these
          >structures and then use a custom comparer to compare instances of the
          >items. Then, the Sort method will do the rest for you.
          >>
          >>
          >--
          > - Nicholas Paldino [.NET/C# MVP]
          > - mvp@spam.guard. caspershouse.co m
          >>
          >"Gary Brown" <garyjbrown@cha rter.netwrote in message
          >news:ef21zzS2H HA.4680@TK2MSFT NGP03.phx.gbl.. .
          >>Hi,
          >>>
          >>I need a stable sort and can find none in the MS libraries.
          >>Is there a simple one available on the internet? It needed
          >>for sorting various lists of maybe 1K elements - mostly
          >>ListView columns.
          >>>
          >>I took an algorithms course many years ago and learned
          >>to really hate writing sort routines or I would just write one.
          >>>
          >>Googles lists many tutorials and conversations but no
          >>methods.
          >>>
          >>Thanks,
          >>Gary
          >>>
          >>>
          >>
          >>
          >
          >

          Comment

          • Brette.Net

            #6
            Re: Stable Sort Method - Where Can I Get One?

            This seems to work on my PC.

            List<Datalist = new List<Data>();

            list.Add(new Data("First"));
            list.Add(new Data("Second")) ;
            list.Add(new Data("Third"));
            Array.Sort(list .ToArray());

            foreach (Data data in list)
            {
            Console.WriteLi ne(data);
            }

            Comment

            • Jon Skeet [C# MVP]

              #7
              Re: Stable Sort Method - Where Can I Get One?

              Brette.Net <Brette.Net@gma il.comwrote:
              This seems to work on my PC.
              >
              List<Datalist = new List<Data>();
              >
              list.Add(new Data("First"));
              list.Add(new Data("Second")) ;
              list.Add(new Data("Third"));
              Array.Sort(list .ToArray());
              >
              foreach (Data data in list)
              {
              Console.WriteLi ne(data);
              }
              That's not actually sorting the list though. It's creating a copy of
              the list as an array, sorting that array, and then printing out the
              (unchanged) list.

              --
              Jon Skeet - <skeet@pobox.co m>
              http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
              If replying to the group, please do not mail me too

              Comment

              • Sir C4

                #8
                Re: Stable Sort Method - Where Can I Get One?

                On Aug 7, 12:59 pm, "Gary Brown" <garyjbr...@cha rter.netwrote:
                Hi,
                >
                I need a stable sort and can find none in the MS libraries.
                Is there a simple one available on the internet? It needed
                for sorting various lists of maybe 1K elements - mostly
                ListView columns.
                >
                I took an algorithms course many years ago and learned
                to really hate writing sort routines or I would just write one.
                >
                Googles lists many tutorials and conversations but no
                methods.
                >
                Thanks,
                Gary
                Have you looked into the Wintellect's Power Collections?
                http://www.wintellect.com/PowerCollections.aspx

                Comment

                • Gary Brown

                  #9
                  Re: Stable Sort Method - Where Can I Get One?


                  "Gary Brown" wrote in message
                  I need a stable sort and can find none in the MS libraries.
                  Is there a simple one available on the internet? It needed
                  Well, I finally bit the bullet and wrote a merge sort. None of
                  the sorts that I found on the internet, Wintellect for example,
                  stated whether they were stable or not. It proved easier to
                  write one than wade through a lot of code to find a stable sort.

                  I finally got some use out my ancient (1974) editions of
                  Knuth's books on algorithms.

                  Thanks to all who responded,
                  Gary


                  Comment

                  • Michael A. Covington

                    #10
                    Re: Stable Sort Method - Where Can I Get One?

                    See also this:

                    <http://www.covingtonin novations.com/michael/blog/0607/index.html#0607 13A>




                    Comment

                    Working...