Skip to content

Commit 029582e

Browse files
declared swap function beforehand to avoid conflicting types warning in some standard compilers
1 parent ddf3334 commit 029582e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sort/bubble_sort.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
void bubblesort(int arr[], int size)
88
{
99
int i, j;
10-
for (i = 0; i < size; i++) // Function where the actual algorithm is implemented
10+
for (i = 0; i < size - 1; i++) // Function where the actual algorithm is implemented
1111
{
12-
for (j = 0; j < size - i; j++)
12+
for (j = 0; j < size - i - 1; j++)
1313
{
1414
if (arr[j] > arr[j+1])
1515
swap(&arr[j], &arr[j+1]);

0 commit comments

Comments
 (0)