@@ -9,17 +9,17 @@ vector<int> counting_sort(vector<int>& nums) {
9
9
10
10
// nums = {5, 0, 1, 2, 3, 5, 3, 0, 9, 4}
11
11
// max = 9
12
- // vector nums contem elementos entre [0 .. max]
12
+ // The vector contains numbers between [0 .. max]
13
13
auto max = *max_element (nums.begin (), nums.end ());
14
14
15
15
16
- // cria um vector com max + 1 posicoes para contar ocorrências de cada elemento
17
- // 0 1 2 3 4 5 6 7 8 9 -> elementos possiveis de ocorrer no vector nums
18
- // counting = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
16
+ // Creates a vector with max + 1 positions to count occurrences of each element
17
+ // 0 1 2 3 4 5 6 7 8 9 -> possible elements to occur in the vector nums
18
+ // Counting = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
19
19
vector<int > counting (max+1 );
20
20
21
21
22
- // conta ocorrencias de cada elemento
22
+ // Counts occurrences of each element
23
23
// nums = {5, 0, 1, 2, 3, 5, 3, 0, 9, 4}
24
24
//
25
25
// 0 1 2 3 4 5 6 7 8 9
@@ -30,8 +30,8 @@ vector<int> counting_sort(vector<int>& nums) {
30
30
}
31
31
32
32
33
- // agora , counting = {2, 3, 4, 6, 7, 9, 9, 9, 9, 10}
34
- // sera utilizado para determinar as posicoes dos elementos no vector ordenado
33
+ // Now , counting = {2, 3, 4, 6, 7, 9, 9, 9, 9, 10}
34
+ // It will be used to determine the positions of the elements in the ordered vector
35
35
for (size_t i = 1 ; i < counting.size (); i++) {
36
36
37
37
counting[i] += counting[i-1 ];
@@ -41,29 +41,29 @@ vector<int> counting_sort(vector<int>& nums) {
41
41
42
42
/*
43
43
44
- O proximo loop coloca os numeros em suas devidas posicoes no vetor ordenado
45
- i = itera pelos elementos de nums
46
- counting[i] -1 é a posicao que o elemento i devee assumir no vetor ordenado
44
+ The next loop places the numbers in their proper positions in the ordered vector
45
+ i = iterates through the elements of nums
46
+ counting[i] -1 is the position that element i must assume in the ordered vector
47
47
48
- Os 3 primeiros passos seriam :
48
+ The first 3 steps would be :
49
49
50
50
nums = {5, 0, 1, 2, 3, 5, 3, 0, 9, 4}
51
51
counting = {2, 3, 4, 6, 7, 9, 9, 9, 9, 10}
52
52
sorted = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
53
53
54
- passo 1:
54
+ Step 1:
55
55
i = 5
56
56
counting[i] => counting[5] => 9
57
57
sorted[9 - 1] => sorted[8] = i => sorted[8] = 5
58
58
sorted = {0, 0, 0, 0, 0, 0, 0, 0, 5, 0}
59
59
60
- passo 2:
60
+ Step 2:
61
61
i = 0
62
62
counting[i] => counting[0] => 2
63
63
sorted[2 - 1] => sorted[1] = i => sorted[1] = 0
64
64
sorted = {0, 0, 0, 0, 0, 0, 0, 0, 5, 0}
65
65
66
- passo 3:
66
+ Step 3:
67
67
i = 1
68
68
counting[i] => counting[1] => 3
69
69
sorted[3 - 1] => sorted[2] = i => sorted[2] = 1
0 commit comments