Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #4104

Re: Did the sort do anything?

From Gene <gene.ressler@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Did the sort do anything?
Date 2011-05-14 21:49 -0700
Organization http://groups.google.com
Message-ID <a5cc61c3-8ac4-46e1-823c-9d3251f9f67a@glegroupsg2000goo.googlegroups.com> (permalink)

Show all headers | View raw


On Tuesday, May 10, 2011 11:06:38 AM UTC-4, Roedy Green wrote:
> Often you sort things when they are already sorted. 
> 
> I am interested in simple algorithms to detect whether the sort
> actually did anything.
> 
> Some suggestions:
> 
> 1. do a pairwise compare of the times before the sort, and if all is
> in order, bypass the sort.

If you suspect that the list is close to sorted, you can do one bubble sort pass moving out-of-place elements to their correct locations.  At the same time you can track whether this pass produces a completely sorted list and call the library sort if that's not the case.

Back to comp.lang.java.programmer | Previous | NextNext in thread | Find similar


Thread

Re: Did the sort do anything? Gene <gene.ressler@gmail.com> - 2011-05-14 21:49 -0700
  Re: Did the sort do anything? Lew <noone@lewscanon.com> - 2011-05-15 07:07 -0400
    Re: Did the sort do anything? Robert Klemme <shortcutter@googlemail.com> - 2011-05-15 14:07 +0200

csiph-web