Question

Develop a Windows Forms application that will allow a user to select between the 5 different...

Develop a Windows Forms application that will allow a user to select
between the 5 different soring algorithms.
• The application’s GUI should include / perform the following:
o A textbox to enter a string value
o A button to submit the string value
o A listbox to store all of the submitted string values. The entries in this
list will always be unsorted, i.e. it should list the entries in the
sequence in which they have been captured.
o A combobox from which to select one of 5 sorting algorithms.
o A button to submit once a sorting algorithm has been selected.
o A listbox to store the sorted results. This listbox will store the results of
sorting the entries from the first listbox, using the selected sorting
algorithm. (Remember to clear this listbox at the start of every new
sort.)
o Once a sort has been completed, a MessageBox should pop up to
display how long the sort has taken in milliseconds. The duration of
the sorting process should start from the beginning of the (sorting)
button click up to when the last entry has been loaded into the
sorted listbox.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Program:

/*
* Program to enter string data
* Sort different sorts and display another list
* Show time in milli seconds in a message box
*/
using System;
using System.Windows.Forms;

namespace SortingInCSharp
{
public partial class frmSort : Form
{
public frmSort()
{
InitializeComponent();
}
//Add each string to unsorted list
private void btnEnter_Click(object sender, EventArgs e)
{
lstUnSorted.Items.Add(txtInput.Text);
txtInput.Text = "";
txtInput.Select();
}
//Add combobox item and start with textbox input selected
private void frmSort_Load(object sender, EventArgs e)
{
txtInput.Select();
cmbSort.Items.Add("Selection Sort");
cmbSort.Items.Add("Insertion Sort");
cmbSort.Items.Add("Bubble Sort");
cmbSort.Items.Add("Heap Sort");
cmbSort.Items.Add("Cycle Sort");
}
//Use different sort methods and their time of execution
//Using combobox selected index for sorting call
private void btnSubmit_Click(object sender, EventArgs e)
{
lstSorted.Items.Clear();
var stopWatch = new System.Diagnostics.Stopwatch(); ;
if (cmbSort.SelectedIndex == 0)
{
stopWatch.Start();
selectionSort();
stopWatch.Stop();
MessageBox.Show(stopWatch.ElapsedMilliseconds.ToString()+" milliseconds");
}
else if (cmbSort.SelectedIndex == 1)
{
stopWatch.Start();
insertionSort();
stopWatch.Stop();
MessageBox.Show(stopWatch.ElapsedMilliseconds.ToString() + " milliseconds");
}
else if (cmbSort.SelectedIndex == 2)
{
stopWatch.Start();
bubbleSort();
stopWatch.Stop();
MessageBox.Show(stopWatch.ElapsedMilliseconds.ToString() + " milliseconds");
}
else if (cmbSort.SelectedIndex == 3)
{
stopWatch.Start();
heapSort();
stopWatch.Stop();
MessageBox.Show(stopWatch.ElapsedMilliseconds.ToString() + " milliseconds");
}
else if (cmbSort.SelectedIndex == 4)
{
stopWatch.Start();
cycleSort();
stopWatch.Stop();
MessageBox.Show(stopWatch.ElapsedMilliseconds.ToString() + " milliseconds");
}
}
//Selection sort implementation
private void selectionSort()
{
for (int i = 0; i < lstUnSorted.Items.Count; i++)
{
lstSorted.Items.Add(lstUnSorted.Items[i].ToString());
}
for (int i = 0; i < lstSorted.Items.Count - 1; i++)
{
int idx = i;
for (int j = i + 1; j < lstUnSorted.Items.Count; j++)
if (lstSorted.Items[j].ToString().CompareTo( lstSorted.Items[idx].ToString())<0)
idx = j;
String temp = lstSorted.Items[idx].ToString(); ;
lstSorted.Items[idx] = lstSorted.Items[i];
lstSorted.Items[i] = temp;
}
}
//Insertion sort
private void insertionSort()
{
for (int i = 0; i < lstUnSorted.Items.Count; i++)
{
lstSorted.Items.Add(lstUnSorted.Items[i].ToString());
}
for (int i = 1; i < lstSorted.Items.Count; i++)
{
string val = lstSorted.Items[i].ToString();
int f = 0;
for (int j = i - 1; j >= 0 && f != 1;)
{
if (val.CompareTo(lstSorted.Items[j].ToString())<0)
{
lstSorted.Items[j + 1] = lstSorted.Items[j];
j--;
lstSorted.Items[j + 1] = val;
}
else f= 1;
}
}
}
//Bubble sort implementation
private void bubbleSort()
{
for (int i = 0; i < lstUnSorted.Items.Count; i++)
{
lstSorted.Items.Add(lstUnSorted.Items[i].ToString());
}
for (int p = 0; p < lstSorted.Items.Count; p++)
{
for (int i = p+1; i < lstUnSorted.Items.Count; i++)
{
if (lstSorted.Items[p].ToString().CompareTo(lstSorted.Items[i].ToString())>0)
{
String t = lstSorted.Items[p].ToString();
lstSorted.Items[p] = lstSorted.Items[i];
lstSorted.Items[i] = t;
}
}
}
}
//Heap sort implementation
public void heapSort()
{
for (int i = 0; i < lstUnSorted.Items.Count; i++)
{
lstSorted.Items.Add(lstUnSorted.Items[i].ToString());
}
int n = lstSorted.Items.Count;
for (int i = n / 2 - 1; i >= 0; i--)
heapify(n, i);

for (int i = n - 1; i >= 0; i--)
{
string temp = lstSorted.Items[0].ToString();
lstSorted.Items[0] = lstSorted.Items[i];
lstSorted.Items[i] = temp;
heapify(i, 0);
}
}
void heapify(int n, int i)
{
int largest = i;
int l = 2 * i + 1;
int r = 2 * i + 2;
if (l < n && lstSorted.Items[l].ToString().CompareTo(lstSorted.Items[largest].ToString())>0)
largest = l;
if (r < n && lstSorted.Items[r] .ToString().CompareTo(lstSorted.Items[largest].ToString())>0)
largest = r;
if (largest != i)
{
string swap = lstSorted.Items[i].ToString();
lstSorted.Items[i] = lstSorted.Items[largest];
lstSorted.Items[largest] = swap;
heapify(n, largest);
}
}
//Ccyle sort implementation
private void cycleSort()
{
for (int i = 0; i < lstUnSorted.Items.Count; i++)
{
lstSorted.Items.Add(lstUnSorted.Items[i].ToString());
}
int w = 0;
for (int i= 0; i <= lstSorted.Items.Count - 2; i++)
{
string item = lstSorted.Items[i].ToString();
int pos =i;
for (int j = i + 1; j < lstSorted.Items.Count; j++)
if (lstSorted.Items[j].ToString().CompareTo(item)<0)
pos++;
if (pos == i)
continue;
while (item.CompareTo(lstSorted.Items[pos].ToString())==0)
pos += 1;
if (pos != i)
{
string temp = item;
item = lstSorted.Items[pos].ToString();
lstSorted.Items[pos] = temp;
w++;
}
while (pos !=i)
{
pos =i;

for (int j = i + 1; j < lstSorted.Items.Count; j++)
if (lstSorted.Items[j].ToString().CompareTo(item)<0)
pos += 1;
while (item.CompareTo(lstSorted.Items[pos].ToString())==0)
pos += 1;

if (item.CompareTo(lstSorted.Items[pos].ToString())!=0)
{
string temp = item;
item = lstSorted.Items[pos].ToString();
lstSorted.Items[pos] = temp;
w++;
}
}
}
}
//Clear items sorted
private void txtInput_MouseEnter(object sender, EventArgs e)
{
lstSorted.Items.Clear();
cmbSort.SelectedItem = "";
}
}
}

PLEASE GIVE POSITIVE RATING.THUMBSUP.THANKYOU...!!

Add a comment
Know the answer?
Add Answer to:
Develop a Windows Forms application that will allow a user to select between the 5 different...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a Wpf application Use Visual Studios 2019 A shipping company receives packages at its headquarters,...

    Create a Wpf application Use Visual Studios 2019 A shipping company receives packages at its headquarters, which functions as its shipping hub. After receiving the packages the company ships them to a distribution center in one of the following states: Alabama, Florida, Georgia, Kentucky, Mississippi, North Carolina, South Carolina, Tennessee, West Virginia or Virginia. The company needs an application to track the packages that pass through its shipping hub. The application generates a package ID number for each package that...

  • Comparison of Sorting Algorithms You are required to implement all the sorting algorithms (Bubble, Selection, Insertion...

    Comparison of Sorting Algorithms You are required to implement all the sorting algorithms (Bubble, Selection, Insertion, Quick, Merge). Take help from lecture slides and welb . You will then create arrays of different sizes as instructed below, test each algorithm on each array and record the execution times of each individual algorithm on each array. . You will report these execution times in a table and then write a report explaining the execution times of the sorting algorithms according to...

  • Design a program that allows you to experiment with different sort algorithms in Java. This program should allow you to...

    Design a program that allows you to experiment with different sort algorithms in Java. This program should allow you to easily plug-in new sort algorithms and compare them. Assume that input data is generated randomly and stored in a text file (have no less than 2000 items to sort). Do not restrict your program to only one data type, or to one ordering relationship. The data type, ordering relationship, and the sorting method must be input parameters for your program....

  • I need the report like this (idea) *Sorting Algorithms: A sorting algorithm is an algorithm that...

    I need the report like this (idea) *Sorting Algorithms: A sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms (such as search and merge algorithms) which require input data to be in sorted lists; it is also often useful for canonical zing data and for producing human-readable output. More formally, the output must satisfy...

  • in JAVA program.Use top-down design to design and implement a program to ask the user to...

    in JAVA program.Use top-down design to design and implement a program to ask the user to enter a list of integers, and then display to the user the mean and median of this list. You should first prompt the user to specify the length of the list of integers. For this assignment, your code should create an array of size 10, and then allow the user to specify the number of integers in their list, up to a maximum of...

  • The purpose of the project is to perform a timing experiment. You are required to complete...

    The purpose of the project is to perform a timing experiment. You are required to complete the following activities: Write a computer program that prompts the user for a number, creates an array for that number of random integers, and then usees the bubble sort to order the array. The program should print out the array prior to the call to the sorting algorithm and afterwards. You can write the program in either Java, C++, C#, or whatever language you...

  • Written in Java Your job is to produce a program that sorts a list of numbers...

    Written in Java Your job is to produce a program that sorts a list of numbers in ascending order. Your program will need to read-in, from a file, a list of integers – at which point you should allow the user an option to choose to sort the numbers in ascending order via one of the three Sorting algorithms that we have explored. Your program should use the concept of Polymorphism to provide this sorting feature. As output, you will...

  • In below C++ sort.cpp 1- Implement the insertion_sort function. 2- Implement the compareSensorPtr function and the...

    In below C++ sort.cpp 1- Implement the insertion_sort function. 2- Implement the compareSensorPtr function and the code in main to create and sort the array of pointers. The places to make modifications are indicated by TODO: comments. You should not have to make modifications anywhere else. 3- what's big O and runtime for 100000 items. #include <iostream> #include <algorithm> #include <numeric> #include <vector> #include <string> #include <cstdlib> #include <cassert> using namespace std; // Set this to false to skip the...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

  • Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one me...

    Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one menu item called Search. Clicking on search should prompt the user using a JOptionPane input dialog to enter a car make. The GUI should then display only cars of that make. You will need to write a second menu...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT