Perbandingan Kompleksitas Waktu Teoretis dan Real Time Algoritma Strand Sort, Sieve Sort, Gnome Sort

A69
-1

LISTING PROGRAM
//Main Form
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.IO;
namespace Sorting_data
{
///
/// Description of MainForm.
///

public partial class MainForm : Form
{
List data = new List();
List data2 = new List();
List data3 = new List();
//string[] data, data2, data3, strand, sieve,
gnome;
int n;
string j;
Random rr = new Random();
ToolTip tooltip = new ToolTip();
Point? prevPosition = null;
public MainForm()
{
//
// The InitializeComponent() call is required
for Windows Forms designer support.
//
InitializeComponent();
//

// TODO: Add constructor code after the
InitializeComponent() call.
//
}
private void button1_Click(object sender,
EventArgs e)
{

Universitas Sumatera Utara

70

richTextBox1.Text = null;
richTextBox2.Text = null;
richTextBox3.Text = null;
GenerateData();
}
private void GenerateData()
{
data.Clear();

data2.Clear();
data3.Clear();
StringBuilder sb = new StringBuilder();
n = Convert.ToInt32(textBox1.Text);
j = RandomString(8 * n);
for (int i = 0; i < n; i++)
{
data.Add(j.Substring(8 * i, 8));
data2.Add(j.Substring(8 * i, 8));
data3.Add(j.Substring(8 * i, 8));
sb.Append(j.Substring(8 * i, 8));
if (i != n - 1)
sb.Append("\n");
}
richTextBox1.Text = sb.ToString();
richTextBox2.Text = sb.ToString();
richTextBox3.Text = sb.ToString();
}
public static string RandomString(int length)
{

Random rr = new Random();
const string chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123
456789";
return new string(Enumerable.Repeat(chars,
length)
.Select(s =>
s[rr.Next(s.Length)]).ToArray());
}
private void button2_Click(object sender,
EventArgs e)
{
Stopwatch sw;
sw = new Stopwatch();
sw.Start();
Sievesort gnome = new Sievesort(data);
data = gnome.prosesSort();
sw.Stop();

Universitas Sumatera Utara


71

textBox2.Text =
sw.ElapsedMilliseconds.ToString();
sw = new Stopwatch();
sw.Start();
gnomeSort gnome1 = new gnomeSort(data2);
gnome1.prosesSort();
sw.Stop();
textBox3.Text =
sw.ElapsedMilliseconds.ToString();
sw = new Stopwatch();
sw.Start();
strandSorting gnome2 = new
strandSorting(data3);
gnome2.prosesSort();
sw.Stop();
textBox4.Text =
sw.ElapsedMilliseconds.ToString();

richTextBox4.Text = "";
richTextBox5.Text = "";
richTextBox6.Text = "";
for (int i = 0; i < data.Count; i++)
{
richTextBox5.Text += data[i] + "\n";
richTextBox4.Text += data3[i] + "\n";
richTextBox6.Text += data2[i] + "\n";
}
}
private void button3_Click(object sender,
EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Text File(*.txt)|*.txt";
if (open.ShowDialog() == DialogResult.OK)
{
data.Clear();
data2.Clear();
data3.Clear();

string temp = "";
StringBuilder sb = new StringBuilder();
FileStream fstream = new
FileStream(open.FileName, FileMode.Open,
FileAccess.ReadWrite);
StreamReader sreader = new
StreamReader(fstream);

Universitas Sumatera Utara

72

sreader.BaseStream.Seek(0,
SeekOrigin.Begin);
while (sreader.Peek() > 0)
{
temp = sreader.ReadLine();
data.Add(temp);
data2.Add(temp);
data3.Add(temp);

sb.Append(temp);
sb.Append("\n");
}
temp = sreader.ReadLine();
sb.Append(temp);
sreader.Close();
richTextBox1.Text = sb.ToString();
richTextBox2.Text = sb.ToString();
richTextBox3.Text = sb.ToString();
}
}
private void button4_Click(object sender,
EventArgs e)
{
SaveFileDialog save = new SaveFileDialog();
save.Filter = "FILE TEXT|*.txt";
save.FileName = "*.txt";
if (save.ShowDialog() == DialogResult.OK)
{
string nama;

nama = save.FileName.Substring(0,
save.FileName.Length - 4) + "_strand.txt";
FileStream fs = new FileStream(nama,
FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(fs);
SeekOrigin sk = new SeekOrigin();
sw.BaseStream.Seek(0, sk);
for (int i = 0; i < data.Count; i++)
{
sw.WriteLine(data[i]+ "\n");
}
sw.Flush();
sw.Close();
nama = save.FileName.Substring(0,
save.FileName.Length - 4) + "_sieve.txt";
fs = new FileStream(nama,
FileMode.OpenOrCreate);
sw = new StreamWriter(fs);
sk = new SeekOrigin();


Universitas Sumatera Utara

73

sw.BaseStream.Seek(0, sk);
for (int i = 0; i < data2.Count; i++)
{
sw.WriteLine(data2[i] + "\n");
}
sw.Flush();
sw.Close();
nama = save.FileName.Substring(0,
save.FileName.Length - 4) + "_gnome.txt";
fs = new FileStream(nama,
FileMode.OpenOrCreate);
sw = new StreamWriter(fs);
sk = new SeekOrigin();
sw.BaseStream.Seek(0, sk);
for (int i = 0; i < data3.Count; i++)
{

sw.WriteLine(data3[i] + "\n");
}
sw.Flush();
sw.Close();
}
}
private void buttonBack_Click(object sender,
EventArgs e)
{
FormHome home = new FormHome();
home.Show();
this.Hide();
}
}
}

Universitas Sumatera Utara

74

//Algoritma Strand Sort
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Sorting_data
{
public class strandSorting
{
Byte[] asciiTemp1, asciiTemp2;
List words = new List();
String stringTemp;
int maxChar;
public strandSorting(List _words) {
words = _words;
}
public List prosesSort()
{
if (words.Count index; k--)

Universitas Sumatera Utara

75

{
words[k] = words[k - 1];
}
words[index] = temp;
}
return words;
}
}
}

Universitas Sumatera Utara

76

//Algoritma Sieve Sort
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Sorting_data
{
public class Sievesort
{
List words = new List();
gnomeSort gnome;
List non_asc;
List asc = new
List();
public Sievesort(List _words)
{
words = _words;
}
public List prosesSort(){
List tempListAsc = new
List();
List tempListNonAsc = new
List();
List tempListMax = new
List();
non_asc = words;
int t = 0;
int s = 1;
do
{
tempListAsc.Add(non_asc[t]);
for (int i = 1; i < non_asc.Count; i++)
{
tempListMax.Add(non_asc[t]);
tempListMax.Add(non_asc[s]);
gnome = new gnomeSort(tempListMax);
if
(gnome.prosesSort()[1].Equals(non_asc[s])) {
tempListAsc.Add(non_asc[s]);
t = s;
s++;
}

Universitas Sumatera Utara

77

else
{
tempListNonAsc.Add(non_asc[s]);
s++;
}
tempListMax = new List();
}
asc.Add(tempListAsc);
non_asc = tempListNonAsc;
tempListAsc = new List();
tempListNonAsc = new List();
t = 0;
s = 1;
} while (non_asc.Count != 0);
words = asc[0];
for(int i = 0; i < asc.Count - 1; i++)
{
for(int j = 0; j < asc[i + 1].Count; j++)
{
for (int k = 0; k < words.Count; k++)
{
tempListMax = new List();
tempListMax.Add(words[k]);
tempListMax.Add(asc[i+1][j]);
gnome = new
gnomeSort(tempListMax);
if
(gnome.prosesSort()[1].Equals(words[k]))
{
words.Insert(k, asc[i +
1][j]);
break;
}
}
}
}
return words;
}
}
}

Universitas Sumatera Utara

78

//Algoritma Gnome Sort
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Sorting_data
{
public class gnomeSort
{
Byte[] asciiTemp1, asciiTemp2;
List words = new List();
String stringTemp;
int maxChar;
public gnomeSort(List _words) {
words = _words;
}
public List prosesSort(){
for (int i = 1; i < words.Count; )
{
asciiTemp1 =
Encoding.ASCII.GetBytes(words[i - 1].ToCharArray());
asciiTemp2 =
Encoding.ASCII.GetBytes(words[i].ToCharArray());
maxChar = asciiTemp1.Length;
if (asciiTemp1.Length >
asciiTemp2.Length)
{
maxChar = asciiTemp2.Length;
}
for (int j = 0; j < maxChar; j++)
{
if (asciiTemp1[j] < asciiTemp2[j])
{
i++;
break;
}
else if (asciiTemp1[j] >
asciiTemp2[j])
{
stringTemp = words[i - 1];
words[i - 1] = words[i];
words[i] = stringTemp;
i = 1;

Universitas Sumatera Utara

79B - 1

break;
}
if (j == maxChar - 1)
{
if (maxChar == asciiTemp1.Length)
{
i++;
}
else if(maxChar ==
asciiTemp2.Length)
{
stringTemp = words[i - 1];
words[i - 1] = words[i];
words[i] = stringTemp;
i = 1;
break;
}
}
}
}
return

words;

}
}
}

Universitas Sumatera Utara

B -80
1
DAFTAR RIWAYAT HIDUP
PERSONAL DATA
Full Name
Nick Name
Place/ Date of Birth
Sex
Religion
Nationality
Address

Mobile Phone
E-mail

: Ruth Stephany Marsaulina Siahaan
: Fanny
: Medan / 01 September 1992
: Wanita
: Kristen Protestan
: Indonesia
: Jl. M. Yakub no.56
Kota Medan.
Provinsi Sumatera Utara, Indonesia
: +62852-6110-5369
: ruthstephany@yahoo.com

EDUCATION
Bachelor of Computer Science
2014-2017
: Universitas Sumatera Utara, Medan
Diploma of Electronic Engineering
2010-2013
: Politeknik Negeri Medan
Higher Secondary Education
2007-2010
: SMA Negeri 7 Medan
Secondary Education
2004 - 2007 : SMP Budi Murni 1 Medan
Primary Education
1998 - 2004 : SD Budi Murni 7 Medan
COMPUTER SKILL
Programming
PHP, C#
Database
MySQL
IDE Software
PHP VB.net, Sharp Develop

Universitas Sumatera Utara

B -22

ORGANIZATIONAL EXPERIENCE

Organization
OSIS SMP
OSIS SMA
PADUAN SUARA SMA
PA SMA
KMK POLMED
HMPS TEKNIK ELEKTRO
BEM POLMED
PADUAN SUARA GEREJA

Position
Anggota
Ketua Departemen Agama Kristen
Bendahara
Anggota
Anggota
Ketua Sie.Humas
Anggota
Anggota

Year
2005-2007
2008-2010
2008-2010
2007-2010
2011-2012
2011-2012
2012-2013
2009-2016

Universitas Sumatera Utara