info:
Ini syntax udah lama. pake yang baru aja >> DISINI <<
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 frm_ss : Form
{
int[] data = new int[5];
int x = 0;
public frm_ss()
{
InitializeComponent();
}
private void btn_input_Click(object sender, EventArgs e)
{
data[x] = int.Parse(txt_input.Text);
x++;
txt_input.Clear();
txt_input.Focus();
if (x == 5)
{
txt_input.Enabled = false;
btn_input.Enabled = false;
}
}
private void btn_hasil_Click(object sender, EventArgs e)
{
int temp;
foreach (int i in data)
{
lb_awal.Items.Add(i);
}
for (int i = 0; i < x; i++)
{
for (int j = 0; j < x; j++)
{
if (data[i] < data[j])
{
temp = data[i];
data[i] = data[j];
data[j] = temp;
}
}
}
foreach (int i in data)
{
lb_akhir.Items.Add(i);
}
}
}
}
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 frm_ss : Form
{
int[] data = new int[5];
int x = 0;
public frm_ss()
{
InitializeComponent();
}
private void btn_input_Click(object sender, EventArgs e)
{
data[x] = int.Parse(txt_input.Text);
x++;
txt_input.Clear();
txt_input.Focus();
if (x == 5)
{
txt_input.Enabled = false;
btn_input.Enabled = false;
}
}
private void btn_hasil_Click(object sender, EventArgs e)
{
int temp;
foreach (int i in data)
{
lb_awal.Items.Add(i);
}
for (int i = 0; i < x; i++)
{
for (int j = 0; j < x; j++)
{
if (data[i] < data[j])
{
temp = data[i];
data[i] = data[j];
data[j] = temp;
}
}
}
foreach (int i in data)
{
lb_akhir.Items.Add(i);
}
}
}
}
Bubble Sort
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 frm_bs : Form
{
int[] data = new int[5];
int x = 0;
public frm_bs()
{
InitializeComponent();
}
private void btn_input_Click(object sender, EventArgs e)
{
data[x] = int.Parse(txt_input.Text);
x++;
txt_input.Clear();
txt_input.Focus();
if (x == 5)
{
txt_input.Enabled = false;
btn_input.Enabled = false;
}
}
private void btn_hasil_Click(object sender, EventArgs e)
{
int temp;
foreach (int i in data)
{
lb_awal.Items.Add(i);
}
for (int i = 0; i <= data.Length-2; i++)
{
for (int j = 0; j <= data.Length-2; j++)
{
if (data[j] > data[j+1])
{
temp = data[j + 1];
data[j + 1] = data[j];
data[j] = temp;
}
}
}
foreach (int i in data)
{
lb_akhir.Items.Add(i);
}
}
}
}
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 frm_bs : Form
{
int[] data = new int[5];
int x = 0;
public frm_bs()
{
InitializeComponent();
}
private void btn_input_Click(object sender, EventArgs e)
{
data[x] = int.Parse(txt_input.Text);
x++;
txt_input.Clear();
txt_input.Focus();
if (x == 5)
{
txt_input.Enabled = false;
btn_input.Enabled = false;
}
}
private void btn_hasil_Click(object sender, EventArgs e)
{
int temp;
foreach (int i in data)
{
lb_awal.Items.Add(i);
}
for (int i = 0; i <= data.Length-2; i++)
{
for (int j = 0; j <= data.Length-2; j++)
{
if (data[j] > data[j+1])
{
temp = data[j + 1];
data[j + 1] = data[j];
data[j] = temp;
}
}
}
foreach (int i in data)
{
lb_akhir.Items.Add(i);
}
}
}
}
Quick Sort
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 frm_qs : Form
{
int[] data = new int[5];
int x = 0;
public frm_qs()
{
InitializeComponent();
}
private void btn_input_Click(object sender, EventArgs e)
{
data[x] = int.Parse(txt_input.Text);
x++;
txt_input.Clear();
txt_input.Focus();
if (x == 5)
{
txt_input.Enabled = false;
btn_input.Enabled = false;
}
}
private void btn_hasil_Click(object sender, EventArgs e)
{
foreach (int i in data)
{
lb_awal.Items.Add(i);
}
Quick_Sort(data, 0, data.Length - 1);
foreach (int i in data)
{
lb_akhir.Items.Add(i);
}
}
private static void Quick_Sort(int[] arr, int left, int right)
{
if (left < right)
{
int pivot = Partition(arr, left, right);
if (pivot > 1)
{
Quick_Sort(arr, left, pivot - 1);
}
if (pivot + 1 < right)
{
Quick_Sort(arr, pivot + 1, right);
}
}
}
private static int Partition(int[] arr, int left, int right)
{
int pivot = arr[left];
while (true)
{
while (arr[left] < pivot)
{
left++;
}
while (arr[right] > pivot)
{
right--;
}
if (left < right)
{
if (arr[left] == arr[right]) return right;
int temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
}
else
{
return right;
}
}
}
}
}
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 frm_qs : Form
{
int[] data = new int[5];
int x = 0;
public frm_qs()
{
InitializeComponent();
}
private void btn_input_Click(object sender, EventArgs e)
{
data[x] = int.Parse(txt_input.Text);
x++;
txt_input.Clear();
txt_input.Focus();
if (x == 5)
{
txt_input.Enabled = false;
btn_input.Enabled = false;
}
}
private void btn_hasil_Click(object sender, EventArgs e)
{
foreach (int i in data)
{
lb_awal.Items.Add(i);
}
Quick_Sort(data, 0, data.Length - 1);
foreach (int i in data)
{
lb_akhir.Items.Add(i);
}
}
private static void Quick_Sort(int[] arr, int left, int right)
{
if (left < right)
{
int pivot = Partition(arr, left, right);
if (pivot > 1)
{
Quick_Sort(arr, left, pivot - 1);
}
if (pivot + 1 < right)
{
Quick_Sort(arr, pivot + 1, right);
}
}
}
private static int Partition(int[] arr, int left, int right)
{
int pivot = arr[left];
while (true)
{
while (arr[left] < pivot)
{
left++;
}
while (arr[right] > pivot)
{
right--;
}
if (left < right)
{
if (arr[left] == arr[right]) return right;
int temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
}
else
{
return right;
}
}
}
}
}
Tidak ada komentar:
Posting Komentar