Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
fix: quick sort C function
Browse files Browse the repository at this point in the history
  • Loading branch information
storopoli committed Oct 17, 2024
1 parent fa8bc0c commit 9c5a23b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions code/c/13-quick_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
int partition(int arr[], int low, int high) {
int pivot = arr[high]; // Choose the last element as pivot
int i = low - 1; // Index of smaller element
int i = low; // Index of smaller element

for (int j = low; j <= high - 1; j++) {
// If current element is smaller than or equal to pivot
Expand All @@ -24,11 +24,11 @@ int partition(int arr[], int low, int high) {
arr[j] = temp;
}
}
// Swap arr[i+1] and arr[high] (or pivot)
int temp = arr[i + 1];
arr[i + 1] = arr[high];
// Swap arr[i] and arr[high] (or pivot)
int temp = arr[i];
arr[i] = arr[high];
arr[high] = temp;
return (i + 1);
return i;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions slides/slides-pt.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2681,7 +2681,7 @@ proposicional pode ser tornada verdadeira* por meio de uma atribuição adequada
```c
int partition(int arr[], int low, int high) {
int pivot = arr[high]; // pivô
int i = (low - 1); // Índice do menor elemento
int i = low; // Índice do menor elemento
for (int j = low; j <= high - 1; j++) {
// Se o elemento atual é menor ou igual ao pivô
Expand All @@ -2692,12 +2692,12 @@ proposicional pode ser tornada verdadeira* por meio de uma atribuição adequada
arr[j] = temp;
}
}
// Troca arr[i + 1] e arr[high] (ou pivô)
int temp = arr[i + 1];
arr[i + 1] = arr[high];
// Troca arr[i] e arr[high] (ou pivô)
int temp = arr[i];
arr[i] = arr[high];
arr[high] = temp;
return (i + 1);
return i;
}
```
]
Expand Down
10 changes: 5 additions & 5 deletions slides/slides.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2660,7 +2660,7 @@ subtrees is at most 1.
```c
int partition(int arr[], int low, int high) {
int pivot = arr[high]; // pivot
int i = (low - 1); // Index of smaller element
int i = low; // Index of smaller element
for (int j = low; j <= high - 1; j++) {
// If current element is smaller than or equal to pivot
Expand All @@ -2671,12 +2671,12 @@ subtrees is at most 1.
arr[j] = temp;
}
}
// Swap arr[i + 1] and arr[high] (or pivot)
int temp = arr[i + 1];
arr[i + 1] = arr[high];
// Swap arr[i] and arr[high] (or pivot)
int temp = arr[i];
arr[i[high];
arr[high] = temp;
return (i + 1);
return i;
}
```
]
Expand Down

0 comments on commit 9c5a23b

Please sign in to comment.