Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8732909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:31:59+00:00 2026-06-13T09:31:59+00:00

I am working with random and sorting methods. So far I have the linear

  • 0

I am working with random and sorting methods. So far I have the linear method working. I am trying to implement a way that will let the user decide which type of sorting to use such as linear, bubble, index, etc. So I have added textBox7 with the label Key and button3 which the user clicks until the find their desired sorting method. When Keytextbox7 has a value chosen then the sort array button2 will execute that particular sorting method. How can I execute a particular sorting method based on the Key value? Below is picture of how I have the windows form set up

CODE

namespace sortmachine
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();

        }


        Stopwatch sw = new Stopwatch();


        Random r = new Random();

        private int size = 0;
        private int max = 0;
        private int ops = 0;
        private int[] ar1;
        private int[] ar2;
        private int[] ar3;

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                size = Convert.ToInt32(textBox2.Text);
                max = Convert.ToInt32(textBox3.Text);
                string s = "";

                ar1 = new int[size];
                ar2 = new int[size];
                ar3 = new int[size];

                for (int i = 0; i < size; i++)
                {
                    int n = r.Next(0, max);
                    ar1[i] = n;
                    ar2[i] = ar1[i];
                }

                for (int i = 0; i < size; i++)
                {
                    s += ar1[i].ToString() + " ";
                }
                listView1.Items.Add(s);
            }
            catch
            {
                MessageBox.Show("Please input information");
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            int min = max;
            int n = 0;
            string s="";

            sw.Start();

            for (int j = 0; j < size; j++)
            {
                for (int i = 0; i < size; i++)
                {
                    if (min > ar2[i])
                    {
                        min = ar2[i];
                        n = i;
                        ops++;
                    }
                    if (min < ar2[i])
                    {
                        ops++;
                    }

                }
                ar2[n]=max;
                ar3[j] = min;
                min = max;
                s += ar3[j] + " ";
            }

            TimeSpan x = sw.Elapsed;
            textBox5.Text = x.ToString();

                listView2.Items.Add(s);
                listView2.Text = s;
                textBox6.Text = Convert.ToString(ops);
                if (checkBox1.Checked==true)
                {
                    textBox1.AppendText(s+Environment.NewLine);
                }
                for (int i = 0; i < size; i++)
                {
                    ar2[i] = ar1[i];
                }
                ops = 0;

        }

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:32:00+00:00Added an answer on June 13, 2026 at 9:32 am

    Id give this a go as it implements what others were suggesting:

    Inside each if conditional you can perform your own logic per sort type. As you can see I have a sorting option selected from the combobox with other buttons to add numbers to my list for sorting and a control to display the results.

    The code is as follows in the Screenshot:

    if(comboBox1.SelectedItem.ToString() == "Linear")
    {
    }
    else if (comboBox1.SelectedItem.ToString() == "Bubble")
    {            
    }
    else if (comboBox1.SelectedItem.ToString() == "Index")
    {
    }
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with a team that have had problems with random failing tests. The
I am currently working on a random number generator script that will generate three
I have found a way that improves (as far as I have tested) upon
I need a working code for a function that will return a random string
I am working with sorting methods and random. Button1 Creates the parameter randomize numbers,
I'm trying to play a random sound onTouch event (currently working), but the sound
I'm currently working on a problem that requires the random selection of an element
Possible Duplicate: Random number generator not working the way I had planned (C#) I
I'm working on a site that has random background images in the container. Every
I have a user give me a random array of objects, I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.