Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!.POSTED!not-for-mail From: Roedy Green Newsgroups: comp.lang.java.programmer Subject: Did the sort do anything? Date: Tue, 10 May 2011 08:06:38 -0700 Organization: Canadian Mind Products Lines: 27 Message-ID: Reply-To: Roedy Green NNTP-Posting-Host: RCd/Ul4tyxGUBII8WGwa5g.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Forte Agent 6.00/32.1186 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3915 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. 2. back a copy of the unsorted list of items. After the sort, do a pairwise compare for identity. If all are identical, the sort did not do anything. 3. write your own sort that has a boolean function you can ask if it moved anything. 4. do some sort of checksum before and after. -- Roedy Green Canadian Mind Products http://mindprod.com How long did it take after the car was invented before owners understood cars would not work unless you regularly changed the oil and the tires? We have gone 33 years and still it is rare to uncover a user who understands computers don't work without regular backups.