Skip to content

Commit ec8491e

Browse files
committed
fix heapsort
1 parent 20443d1 commit ec8491e

File tree

2 files changed

+3
-3
lines changed
  • src_ordenacao_alianca_rebelde_algoritmo2

2 files changed

+3
-3
lines changed

src_ordenacao_alianca_rebelde_algoritmo2/main.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ void heapify(vector<Civilization> &vec, int n, int i) {
1818
int largest = i;
1919
int l = 2 * i + 1;
2020
int r = 2 * i + 2;
21-
if (l < n && mustSwap(vec[l], vec[largest]))
21+
if (l < n && !mustSwap(vec[l], vec[largest]))
2222
largest = l;
2323

24-
if (r < n && mustSwap(vec[r], vec[largest]))
24+
if (r < n && !mustSwap(vec[r], vec[largest]))
2525
largest = r;
2626
if (largest != i) {
2727
swap(vec[i], vec[largest]);
@@ -91,7 +91,7 @@ int main() {
9191
while (scanf("%s %i %i", &input, &distance, &size) != EOF) {
9292
civilizations.push_back(new Civilization(input, distance, size));
9393
}
94-
int MAX_LENGTH = civilizations.size() - 1;
94+
int MAX_LENGTH = civilizations.size();
9595
heapSort(civilizations, MAX_LENGTH);
9696
for (auto &&civilization : civilizations) {
9797
cout << civilization.getName().c_str() << " " << civilization.getDistance() << " " << civilization.getSize()
192 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)