extern "C"
{
void bubble_sort(int a[], int n);
void select_sort(int a[], int n);
void print_array(int a[], int n);
};
#include "sort_algorithm.h"
#include <stdio.h>
void bubble_sort(int a[], int n)
{
int i, j, temp;
for (j=0; j<n-1; j++)
{
for (i=0; i<n-j-1; i++)
{
if (a[i] > a[i+1])
{
temp = a[i+1];
a[i+1] = a[i];
a[i] = temp;
}
}
}
}
void select_sort(int a[], int n)
{
int i, j, temp;
for (i=0; i<n-1; i++)
{
for (j=i+1; j<n; j++)
{
if (a[i] > a[j])
{
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
}
void print_array(int a[], int n)
{
for (int i=0; i<n; i++)
{
printf("%d\r\n", a[i]);
}
}
#include <stdio.h>
#include <stdlib.h>
#define ARRAY_SIZE(array, T) (sizeof(array)/sizeof(T))
#include "sort_algorithm.h"
void test_bubble_sort()
{
int array[] = {3, 6, 2, 7, 1};
int size = ARRAY_SIZE(array, int);
bubble_sort(array, sizeof(array)/sizeof(int));
print_array(array, sizeof(array)/sizeof(int));
}
void test_select_sort()
{
int array[] = {3, 6, 2, 7, 1};
select_sort(array, sizeof(array)/sizeof(int));
print_array(array, sizeof(array)/sizeof(int));
}
int main()
{
test_bubble_sort();
test_select_sort();
system("pause");
return 0;
}