编译器是c++ builder最新版
TForm5 *Form5;
char list [9] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'};
static int count=0;
void SWAP(char x,char y,char tmp)
{
tmp=x;
x=y;
y=tmp;
}
void perm(char *list, int k, int n)
{ int i,tmp;
if (k == n-1)
{ String a = list;
a = a.SubString(1, n);
Form5->Memo1->Lines->Add(a+" ["+IntToStr(count++)+"]");
}
else
{ for (i=k; i<n; i++)
{ SWAP(list[k], list[i], tmp);
perm(list, k+1, n);
SWAP(list[k], list[i], tmp);
}
}
}
//---------------------------------------------------------------------------
__fastcall TForm5::TForm5(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm5::Button1Click(TObject *Sender)
{
int k = StrToInt(Edit1->Text);
int n = StrToInt(Edit2->Text);
perm(list, k, n );
}
不知道是哪个地方出了问题 执行出来总是ABCD 这一个顺序
希望有大佬帮忙看一下