Click here to Skip to main content
16,012,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need that code which enable me only to show that possible paths between number of N numbers / nodes as a permutation andcombination,
only the ListBox code
..............................
thatis for permutation Button solving :
C#
private void Btn_Permutation_Solve_Click(object sender, EventArgs e)
        {
            long n = 0, r = 0;
            long result;
            //int List_Result = 0;

            try
            {
                n = long.Parse(Txt_Permutation_Source.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Invalid Number");
            }

            try
            {
                r = long.Parse(Txt_Permutation_Destination.Text);
                result = Operations_Class.Permutation(n, r);
                Txt_Permutation_Result.Text = result.ToString();
            }
            catch (FormatException)
            {
                MessageBox.Show("Invalid Number");
            }

--------------------------------
and that's for combination Button solving :
C#
private void Btn_Combination_Solve_Click(object sender, EventArgs e)
        {
            long n = 0, r = 0;
            long result ;
            try
            {
             -   n = long.Parse(Txt_Combination_Source.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Invalid Number");
            }
            try
            {
                r = long.Parse(Txt_Combination_Destination.Text);
                result = Operations_Class.Combination(n, r);
                Txt_Combination_Result.Text = result.ToString();
            }
            catch (FormatException)
            {

                MessageBox.Show("Invalid Number");
            }
            //----------------------------------------------------------------ListBox
            string JoinedLetters = Txt_Combination_Source.Text;
            List<char> SplitLetters = JoinedLetters.ToList();
            int WordLength = SplitLetters.Count;
            int[] Number = new int[WordLength];
            listBox1.DataSource = null;
            listBox1.Items.Clear();
            listBox1.Refresh();
            results = new List<string>();
            for (int Comb = 1; Comb <= WordLength; Comb++)
            {
                pCombinations = pCombinations * Comb;
            }
            string word = "";
            count = 0;
            permutations(WordLength, SplitLetters, word);
            listBox2.DataSource = results;
            progressBar1.Value = (int)(((count - 1) / pCombinations) * 100);

            }

--------------------------------------
but to show all of the operations happening before calculating the permutation and combination in a listbox, we have to edit that code under the comment
"//---------ListBox"
so what can i can do to perform that, your response already will be appreciated
Posted
Comments
PIEBALDconsult 4-Dec-14 23:57pm    
Do you just want the number of posibilities? Or all the actual posibilities?
I don't recommend the latter, as the number grows quickly.
prof-mohamed atef 5-Dec-14 0:06am    
if i asked to do permutation for this strings : "ab" in the list box it must permute them and show them as : [ab, ba], and in the textbox it will show the number of this operations ... that's all
PIEBALDconsult 5-Dec-14 0:08am    
If it only needs to display the number of them, then it can calculate that, it doesn't need to actually iterate them.
prof-mohamed atef 5-Dec-14 0:21am    
i already have calculated its number, but i need to iterate them on a ListBox
PIEBALDconsult 5-Dec-14 0:22am    
It gets big fast.

1 solution

There are several articles on CP that cover Permutations and Combinations, mine is:

Non-recursive Permutations and Combinations[^]

You will likely fail your class if you try to turn it in as your own.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900