s c h e m a t i c s : c o o k b o o k

/ StringChapter / Cookbook.StringRecipeSortingListOfStrings

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

Sorting a list of strings

Problem

Sort a list of strings.

Solution

Use the sort operation in the list collection list.ss.

> (require (lib "compat.ss" "mzlib"))
> (sort string<=? (list "foo" "bar" "baz" "qux"))
("bar" "baz" "foo" "qux")
> (sort string>=? (list "foo" "bar" "baz" "qux"))
("qux" "foo" "baz" "bar")

Discussion

The sort operation uses the merge-sort algorithm, which takes time O(n log n) where n is the length of the list.

-- JensAxelSoegaard - 17 Apr 2004

-- ChrisWarrington - 13 Dec 2006

CookbookForm
TopicType: Recipe
ParentTopic: StringOther
TopicOrder: 075

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest