Insertion Sort C#
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace sorting.examples{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){char[] delimiterChars = { ' ', ',', '.', ':', '\t' };string text = textBox1.Text;string[] words = text.Split(delimiterChars);int[] intValues = new int[words.Length];for (int i = 0; i < words.Length; i++){intValues[i] = Convert.ToInt32(words[i]);}int j,temp;for ( j = 1; j < intValues.Length; j++) {for (int i = 0; i < intValues.Length-j; i++){if (intValues[i] > intValues[i + 1]){temp = intValues[i + 1];intValues[i + 1] = intValues[i];intValues[i] = temp;}}}var result = string.Join(",", intValues);textBox2.Text = result;}private void textBox1_TextChanged(object sender, EventArgs e){}private void textBox2_TextChanged(object sender, EventArgs e){}}}Bubble Sort C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace sorting.examples
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
char[] delimiterChars = { ' ', ',', '.', ':', '\t' };
string text = textBox1.Text;
string[] words = text.Split(delimiterChars);
int[] intValues = new int[words.Length];
for (int i = 0; i < words.Length; i++)
{
intValues[i] = Convert.ToInt32(words[i]);
}
int j,temp;
for ( j = 1; j < intValues.Length; j++) {
for (int i = 0; i < intValues.Length-j; i++)
{
if (intValues[i] > intValues[i + 1])
{
temp = intValues[i + 1];
intValues[i + 1] = intValues[i];
intValues[i] = temp;
}
}
}
var result = string.Join(",", intValues);
textBox2.Text = result;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
}
}