Sign in Join
Wiki copytemporary

Counting sort/fr: what changed

Revision 2 to 3. 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.
2-
3-## Contents
4-
5- * 1 Propriété
6- * 2 unité UCountingSortExtra.pas
7- * 3 unité UCountingSort.pas
8- * 4 Exemple d'emploi
1+Le tri par comptage est algorithme de tri sur les entiers.
92
103## Propriété
114
12- * Très rapide
13- * Seulement avec de petits entiers
5+- Très rapide
6+- Seulement avec de petits entiers
147
158## unité UCountingSortExtra.pas
16-```
9+
10+``` pascal
11+
1712unit UCountingSortExtra;
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.
38-```
3913
40-
14+interface
4115
42-## unité UCountingSort.pas
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.
4332```
33+
34+## unité UCountingSort.pas
35+
36+``` pascal
37+
4438unit UCountingSort;
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;
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
6359 begin
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;
60+ if a[ i ] < min then min := a[ i ];
61+ if a[ i ] > max then max := a[ i ];
8262 end;
83-
84- 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.
8577```
8678
8779## Exemple d'emploi
88-```
80+
81+``` pascal
82+
8983uses
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 );
84+ UCountingSort
85+
86+ ...
87+
88+var
89+
90+ a: array[0..100] of integer;
91+
92+begin
93+
94+ ...
95+
96+ CountingSort( a );
10497```
10598
10699---
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).*
100+*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).*

Back to history