slamat bertemu kembali dengan saya..kali ini saya akan berbagi tentang tugas kuliah saya..tentang pengurutan data atau sorting dengan menggunaka v.studio 2012. c# windows form. buatlah form seperti gambar diatas lalu ketikan coding di bawah ini :)
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
{
public partial class Form1 : Form
{
int y;
int[] data;
public Form1()
{
InitializeComponent();
}
private void BT_OK_Click(object sender, EventArgs e)
{
int[] data = new int[TXT_INPUT.Text.Length];
for(int a=0; a<= data.Length-1;a++)
{
data[a] = int.Parse(TXT_INPUT.Text.Substring(a,1));
}
listView1.Items.Clear();
for (int i = 0; i < data.Length; i++)
{
for (int j = 0; j < data.Length; j++)
{
if (data[i] > data[j])
{
y = data[i];
data[i] = data[j];
data[j] = y;
}
string output = "";
for (int a = 0; a <= data.Length - 1; a++)
{
output += data[a].ToString();
}
listView1.Items.Add(output);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
int[] data = new int[TXT_INPUT.Text.Length];
for (int a = 0; a <= data.Length - 1; a++)
{
data[a] = int.Parse(TXT_INPUT.Text.Substring(a, 1));
}
LV_HASIL.Items.Clear();
for (int i = 0; i < data.Length; i++)
{
for (int j = 0; j < data.Length; j++)
{
if (data[i] < data[j])
{
y = data[i];
data[i] = data[j];
data[j] = y;
}
string output = "";
for (int a = 0; a <= data.Length - 1; a++)
{
output += data[a].ToString();
}
LV_HASIL.Items.Add(output);
}
}
}
}
}
Sign up here with your email