mohsen.khodaparast
پنج شنبه 08 بهمن 1388, 11:47 صبح
شرمنده سوال قبلی بهم ریخته فرستاده شد ، دوباره می فرستم .
معادل دستورات زیر که به سی شارپ است در جاوا چیست ؟ فوری .... خواهشن .... خیلی مهم:عصبانی++:
void swap(ref string a, ref string b)
{
string temp = a;
a = b;
b = temp;
}
//================================
void perm(string[] a, int k, ListBox list)
{
string res = "";
if (k == a.Length - 1)
{
foreach (string i in a)
{
res += i.ToString();
}
res += "\r\n";
list.Items.Add(res);
res = "";
}
else
{
for (int i = k; i < a.Length; i++)
{
swap(ref a[i], ref a[k]);
perm(a, k + 1, list);
swap(ref a[i], ref a[k]);
}
}
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
int n = Convert.ToInt32(textBox2.Text.Length);
string[] a = new string[n];
for (int i = 0; i < n; i++)
a[i] = textBox2.Text[i].ToString();
perm(a, 0, listBox1);
label1.Text = listBox1.Items.Count.ToString() + " حالت ";
}:گریه:
معادل دستورات زیر که به سی شارپ است در جاوا چیست ؟ فوری .... خواهشن .... خیلی مهم:عصبانی++:
void swap(ref string a, ref string b)
{
string temp = a;
a = b;
b = temp;
}
//================================
void perm(string[] a, int k, ListBox list)
{
string res = "";
if (k == a.Length - 1)
{
foreach (string i in a)
{
res += i.ToString();
}
res += "\r\n";
list.Items.Add(res);
res = "";
}
else
{
for (int i = k; i < a.Length; i++)
{
swap(ref a[i], ref a[k]);
perm(a, k + 1, list);
swap(ref a[i], ref a[k]);
}
}
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
int n = Convert.ToInt32(textBox2.Text.Length);
string[] a = new string[n];
for (int i = 0; i < n; i++)
a[i] = textBox2.Text[i].ToString();
perm(a, 0, listBox1);
label1.Text = listBox1.Items.Count.ToString() + " حالت ";
}:گریه: