Sign in Join
Wiki copytemporary

Counting sort/fr: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-Le tri par comptage est algorithme de tri sur les entiers.
1+Le tri par comptage est algorithme de tri sur les entiers.
22
3-## Propriété
3+## Contents
44
5-- Très rapide
6-- Seulement avec de petits entiers
5+ * 1 Propriété
6+ * 2 unité UCountingSortExtra.pas
7+ * 3 unité UCountingSort.pas
8+ * 4 Exemple d'emploi
79
8-## unité UCountingSortExtra.pas
10+## Propriété
911
10-``` pascal
12+ * Très rapide
13+ * Seulement avec de petits entiers
1114
15+## unité UCountingSortExtra.pas
16+```
1217unit UCountingSortExtra;
13-
14-interface
15-
16-type
17- // data type
18- TItemCountingSort=integer;
19-
20-// sort order
21-function IsAscendingCountingSort: boolean; inline;
22-
23-implementation
24-
25-// sort order
26-function IsAscendingCountingSort: boolean; inline;
27-begin
28- result := true;
29-end;
30-
31-end.
18+
19+
20+ interface
21+
22+ type
23+ // data type
24+ TItemCountingSort=integer;
25+
26+ // sort order
27+ function IsAscendingCountingSort: boolean; inline;
28+
29+ implementation
30+
31+ // sort order
32+ function IsAscendingCountingSort: boolean; inline;
33+ begin
34+ result := true;
35+ end;
36+
37+ end.
3238```
3339
34-## unité UCountingSort.pas
35-
36-``` pascal
40+
3741
42+## unité UCountingSort.pas
43+```
3844unit UCountingSort;
39-
40-interface
41-
42-uses
43- UCountingSortExtra;
44-
45-// sorting function
46-procedure CountingSort( var a: array of TItemCountingSort );
47-
48-implementation
49-
50-procedure CountingSort( var a: array of TItemCountingSort );
51-var
52- min, max : TItemCountingSort;
53- count_a : array of integer;
54- i, j, z : integer;
55-begin
56- min := high( a );
57- max := min;
58- for i := low( a ) to high( a ) do
45+
46+
47+ interface
48+
49+ uses
50+ UCountingSortExtra;
51+
52+ // sorting function
53+ procedure CountingSort( var a: array of TItemCountingSort );
54+
55+ implementation
56+
57+
58+ procedure CountingSort( var a: array of TItemCountingSort );
59+ var
60+ min, max : TItemCountingSort;
61+ count_a : array of integer;
62+ i, j, z : integer;
5963 begin
60- if a[ i ] < min then min := a[ i ];
61- if a[ i ] > max then max := a[ i ];
64+ min := high( a );
65+ max := min;
66+ for i := low( a ) to high( a ) do
67+ begin
68+ if a[ i ] < min then min := a[ i ];
69+ if a[ i ] > max then max := a[ i ];
70+ end;
71+ SetLength( count_a, max - min + 1);
72+ for i := 0 to ( max - min ) do count_a[ i ] := 0;
73+ for i := low( a ) to high( a ) do
74+ count_a[ a[ i ] - min ] := count_a[ a[ i ] - min ] + 1;
75+ if IsAscendingCountingSort then z:= low( a ) else z := high( a );
76+ for i := min to max do
77+ for j := 0 to ( count_a[ i - min ] - 1 ) do
78+ begin
79+ a[ z ] := i;
80+ if IsAscendingCountingSort then inc( z ) else dec( z );
81+ end;
6282 end;
63- SetLength( count_a, max - min + 1);
64- for i := 0 to ( max - min ) do count_a[ i ] := 0;
65- for i := low( a ) to high( a ) do
66- count_a[ a[ i ] - min ] := count_a[ a[ i ] - min ] + 1;
67- if IsAscendingCountingSort then z:= low( a ) else z := high( a );
68- for i := min to max do
69- for j := 0 to ( count_a[ i - min ] - 1 ) do
70- begin
71- a[ z ] := i;
72- if IsAscendingCountingSort then inc( z ) else dec( z );
73- end;
74-end;
75-
76-end.
83+
84+ end.
7785```
7886
7987## Exemple d'emploi
80-
81-``` pascal
82-
88+```
8389uses
84- UCountingSort
85-
86- ...
87-
88-var
89-
90- a: array[0..100] of integer;
91-
92-begin
93-
94- ...
95-
96- CountingSort( a );
90+ UCountingSort
91+
92+ ...
93+
94+ var
95+
96+ a: array[0..100] of integer;
97+
98+
99+ begin
100+
101+ ...
102+
103+ CountingSort( a );
97104```
98105
99-\
100-
101106---
102-*From the Free Pascal wiki, page "Counting sort/fr", as it stood on 2020-02-12 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
107+*From the Free Pascal wiki, page "Counting sort/fr", as the Internet Archive kept it on 2023-03-22. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history