void __fastcall TForm1::Button1Click(TObject *Sender)
{ int i, top, count = 0;
int Queen[max_size];
int n = Edit1->Text.ToInt();
for (i=1; i<=n; i++) Queen[i] = 0;
top = 1;
while (top > 0)
{ Queen[top] += 1;
if (Queen[top] > n)
Queen[top--] = 0;
else
if (safety(Queen, top))
{ top++;
if (top == n+1)
{ count++;
print_Queen(Queen, n, count);
Queen[top--] = 0;
}
}
}
Memo1->Lines->Add("#Solutions="+IntToStr(count)+ " for the "+IntToStr(n)+"-Queen problem");
Memo2->Lines->Add("#Solutions="+IntToStr(count)+ " for the "+IntToStr(n)+"-Queen problem");
}