update
This commit is contained in:
parent
1f1ad49427
commit
6f050a029e
2496 changed files with 37609 additions and 3031 deletions
|
|
@ -1,7 +1,8 @@
|
|||
import std.stdio, std.string, std.algorithm, std.typecons;
|
||||
|
||||
void main() {
|
||||
auto data = "here are Some sample strings to be sorted".split();
|
||||
data.schwartzSort!(s => tuple(-s.length, s.toUpper()))();
|
||||
writeln(data);
|
||||
"here are Some sample strings to be sorted"
|
||||
.split
|
||||
.schwartzSort!q{ tuple(-a.length, a.toUpper) }
|
||||
.writeln;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
#lang racket
|
||||
|
||||
;; Using a combination of the two comparisons
|
||||
(define (sort1 words)
|
||||
(sort words (λ(x y)
|
||||
(define xl (string-length x)) (define yl (string-length y))
|
||||
(or (> xl yl) (and (= xl yl) (string-ci<? x y))))))
|
||||
(sort1 '("Some" "pile" "of" "words"))
|
||||
;; -> '("words" "pile" "Some" "of")
|
||||
|
||||
;; Doing two sorts, relying on `sort's stability
|
||||
(define (sort2 words)
|
||||
(sort (sort words string-ci<?) > #:key string-length))
|
||||
(sort2 '("Some" "pile" "of" "words"))
|
||||
;; -> '("words" "pile" "Some" "of")
|
||||
Loading…
Add table
Add a link
Reference in a new issue