下面为组合算法实现:
#include<stdio.h>
int g_array[3];
int len = 3;
void combine(int begin, int count, int array[], int size)//cout可选数目
{
if (count == len)
{
for (int j = 0; j < count; j++)
{
printf("%d ", g_array[j]);
}
printf("\n");
}
else
{
for (int i = begin; i < size - len + 1 + count; i++)
{
g_array[count] = array[i];
combine(i + 1, count + 1, array, size);
}
}
}
int main()
{
int array[5] = { 1, 2, 3, 4, 5 };
combine(0, 0, array, 5);
return 0;
}