In: Computer Science
A, B: Design and Implement a C# windows form
application to ask the user for 10 integer numbers, sort them in
ascending order and display the sorted list. Use bubble sort
technique to sort the array elements and do not use any built-in
sort method to sort the array elements.
[02]
C: Test and evaluate your program by inputting variety
of values.
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1: Form
{
public Form1()
{
InitializeComponent();
FillArray();
}
static int[] arr= new int[10];
private void FillArray()
{
for(i=0;i<10;i++)
{
arr[i] = Convert.ToInt32(Console.ReadLine());
}
}
private void btnOne_Click(object sender, EventArgs e)
{
int len,i,j,temp;
Console.WriteLine("Original array :");
foreach (int val in arr)
Console.Write(val + " ");
for ( j = 0; j <= arr.Length - 2; j++)
{
for ( i = 0; i <= arr.Length - 2; i++)
{
if (arr[i] > arr[i + 1])
{
temp = arr[i + 1];
arr[i + 1] = arr[i];
arr[i] = temp;
}
}
}
Console.WriteLine("\n"+"Sorted array :");
foreach (int val in arr)
Console.Write(val + " ");
Console.Write("\n");
}
}
}
input
4 10 2 5 3 Input number of values to be sorted:Input 4 strings below : Original array : 10 2 5 3 Sorted array : 2 3 5 10
8 10 -2 5 2 1 -8 0 6 Input number of values to be sorted:Input 8 strings below : Original array : 10 -2 5 2 1 -8 0 6 Sorted array : -8 -2 0 1 2 5 6 10