namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
private int n;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
string scrambledWord = textBox1.Text;
if (e.KeyCode == Keys.Enter)
{
label3.Text = scrambledWord;
int n = scrambledWord.Length;
permute(scrambledWord, 0, n - 1);
}
}
private void permute(String scrambledWord,
int l, int r)
{
if (l == r)
label3.Text = scrambledWord;
else
{
for (int i = l; i <= r; i++)
{
scrambledWord = swap(scrambledWord, l, i);
permute(scrambledWord, l + 1, r);
scrambledWord = swap(scrambledWord, l, i);
}
}
}
/**
* Swap Characters at position
* @param a string value
* @param i position 1
* @param j position 2
* @return swapped string
*/
public static String swap(String a,
int i, int j)
{
char temp;
char[] charArray = a.ToCharArray();
temp = charArray[i];
charArray[i] = charArray[j];
charArray[j] = temp;
string s = new string(charArray);
return s;
}
}
}
It is only printing the first line of the permutation, I would like it to print all the permutations. I am new to WinForms. Pls help, Thank you!