char chars[anum];
int ptr=K
void comb(int N,int K)
{
if(K<=0)
{
printf("%s\n",chars); //输出并退出
return; //goback
}
chars[--ptr]=N+'0'; //从后往前生成一个数
comb(N-1,K-1); // 递归调用,生成前面K-1个数
ptr++;
if(N>K) comb(N-1,K); //如果第N位还没有达到最小植,继续向下取植
}
comb(6,3)的输出结果:
456
356
256
156
346
246
146
236
136
126
345
245
145
235
135
125
234
134
124
123
int ptr=K
void comb(int N,int K)
{
if(K<=0)
{
printf("%s\n",chars); //输出并退出
return; //goback
}
chars[--ptr]=N+'0'; //从后往前生成一个数
comb(N-1,K-1); // 递归调用,生成前面K-1个数
ptr++;
if(N>K) comb(N-1,K); //如果第N位还没有达到最小植,继续向下取植
}
comb(6,3)的输出结果:
456
356
256
156
346
246
146
236
136
126
345
245
145
235
135
125
234
134
124
123
帮你译几句吧,你再调一下就OK啦
VC:
chars[--ptr]=N+'0'
VB:
ptr=ptr-1
chars(ptr)=N+48VC:ptr++;
VB:ptr=ptr+1VC:return
vb:exit subVC:char chars[anum];
VB: dim chars(anum) as byte
Option Explicit
Dim chars() As String
Dim p As IntegerSub main()
Dim N As Integer
Dim K As Integer
N = 6: K = 3
ReDim chars(N * K - 1)
p = K
Call comb(N, K)End SubSub comb(ByVal N As Integer, ByVal K As Integer)
If (K <= 0) Then
Dim a As Integer
For a = 0 To UBound(chars)
Debug.Print chars(a);
Next a
Debug.Print
Exit Sub
End If
chars(p) = N & " " '//从后往前生成一个数
p = p - 1
Call comb(N - 1, K - 1) '//递归调用,生成前面K-1个数
p = p + 1
If (N > K) Then
Call comb(N - 1, K) '//如果第N位还没有达到最小植,继续向下取植
Else
End If
End Sub