import random print Sort by count size 10 diap 50 Set randomless array

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import random;
print "Sort by count";
size = 10;
diap = 50;
# Set randomless array[1..size] with [1..diap] diapason
a = [ random.randint(1,diap) for i in xrange(0,size-1) ];
print a;
# Set structured array[1..diap]
b = [ 0 for i in xrange(0,diap+1) ];
# Count into b-array
for x in xrange(0,size-1): b[a[x]] += 1;
# Put into a-array
count = 0;
for x in xrange(0,diap+1):
if (b[x]>0):
for y in xrange(0,b[x]):
a[count] = x;
count += 1;
print a;