Skip to content

Commit e7e550f

Browse files
committed
Translated InsertionSort
1 parent c0ff148 commit e7e550f

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/cpp/InsertionSort.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,40 @@
33

44
using namespace std;
55

6-
void insertionSort(vector<int> &vetor) {
6+
void insertionSort(vector<int> &vector) {
77

8-
for (uint32_t indice = 1; indice < vetor.size(); indice++)
8+
for (uint32_t index = 1; index < vector.size(); index++)
99
{
10-
int chave = vetor[indice];
11-
int i = indice - 1;
10+
int key = vector[index];
11+
int i = index - 1;
1212

13-
while (i >= 0 && vetor[i] > chave)
13+
while (i >= 0 && vector[i] > key)
1414
{
15-
vetor[i+1] = vetor[i];
15+
vector[i+1] = vector[i];
1616
i--;
1717
}
1818

19-
vetor[i+1] = chave;
19+
vector[i+1] = key;
2020
}
2121
}
2222

23-
void showVector(vector<int> vetor)
23+
void showVector(vector<int> vector)
2424
{
25-
for (uint32_t i = 0; i < vetor.size(); ++i)
25+
for (uint32_t i = 0; i < vector.size(); ++i)
2626
{
27-
cout << vetor[i] << ", ";
27+
cout << vector[i] << ", ";
2828
}
2929
cout << "\n";
3030
}
3131

3232
int main()
3333
{
34-
vector<int> vetor;
34+
vector<int> vector;
3535
for (uint32_t i = 0; i < 10; ++i)
3636
{
37-
vetor.push_back(rand() % 100);
37+
vector.push_back(rand() % 100);
3838
}
39-
showVector(vetor);
40-
insertionSort(vetor);
41-
showVector(vetor);
39+
showVector(vector);
40+
insertionSort(vector);
41+
showVector(vector);
4242
}

0 commit comments

Comments
 (0)