Skip to content

Commit 54c591f

Browse files
author
MayuriNFC
committed
modified: c/bubblesort/include/bubblesort.h
modified: c/bubblesort/src/bubble.c
1 parent 2d374f4 commit 54c591f

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

c/bubblesort/include/bubblesort.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
#define _bubblessort_h
33
#include <stdio.h>
44
#include <stdlib.h>
5-
void *bubblesort(int *array);
6-
#endif
5+
void bubblesort(int *array, int size);
6+
#endif

c/bubblesort/src/bubble.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
#include "../include/bubblesort.h"
22
int main()
33
{
4-
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
4+
int a[] = {5, 3, 7, 9, 6, 8, 1, 4, 2, 10};
55
int i;
6-
for (i = 0; i < sizeof(a) / sizeof(a[0]); i++)
6+
int size = sizeof(a)/sizeof(a[0]);
7+
for (i = 0; i < size; i++)
78
{
9+
bubblesort(a,10);
810
printf("%d\n", a[i]);
911
}
1012
return 0;
1113
}
12-
void *bubblesort(int array[])
14+
void bubblesort(int array[],int size)
1315
{
1416
int i, j, temp;
15-
for (i = 0; i < sizeof(array) / sizeof(array[0]); i++)
17+
for (i = 0; i < size; i++)
1618
{
17-
for (j = 0; j < sizeof(array) / sizeof(array[0]) - i - 1; j++)
19+
for (j = 0; j < size - i - 1; j++)
1820
{
1921
if (array[j] > array[j + 1])
2022
{
@@ -24,4 +26,4 @@ void *bubblesort(int array[])
2426
}
2527
}
2628
}
27-
}
29+
}

0 commit comments

Comments
 (0)