可以讲一下这第一个代码和第二个冒泡排序程序的区别吗?
第一个:#include <stdio.h>
#define SIZE 10
void bubbleSort(int * const array, const size_t size);
int main(void)
{
int i;
int a[SIZE] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
puts("Data items in original order");
for(size_t i = 0; i < SIZE; ++i);
{
int i;
printf("%4d", a[i]);
}
bubbleSort(a, SIZE);
puts("\nData items in ascending order");
for (size_t i = 0; i < SIZE; ++i);
{
printf("%4d", a[i]);
}
puts("");
}
void bubbleSort(int * const array, const size_t size)
{
unsigned int pass = 0;
void swap(int *element1Ptr, int *element2Ptr);
for (pass < size - 1;++pass;);
{
int j;
for (size_t j = 0; j < size - 1; ++j);
{
int j;
if (array[j] > array[j + 1])
{
}
}
}
}
第二个:
3#include <stdio.h>
4#define SIZE 10
5
6// function main begins program execution
7int main(void)
8 {
9 // initialize a
10 int a[SIZE] = {2, 6, 4, 8, 10, 12, 89, 68, 45, 37};
11
12 puts("Data items in original order");
13
14// output original array
15for (size_t i = 0; i < SIZE; ++i) {
16 printf("%4d", a[i]);
17 }
18
19// bubble sort
20// loop to control number of passes
24
36 puts("\nData items in ascending order");
37
38// output sorted array
39for (size_t i = 0; i < SIZE; ++i) {
40 printf("%4d", a[i]);
41 }
42
43 puts("");
44 }