namespace Praktikum_5_1_13050974024
{
class Program
{
static void Main(string[] args)
{
int angka, x;
Console.WriteLine();
Console.WriteLine(" ==========Metode Bubble Sort==============");
Console.WriteLine();
Console.Write(" Masukkan Banyak Angka : ");
angka = int.Parse(Console.ReadLine());
int[] array = new int[angka];
Console.WriteLine();
for (x = 0; x < angka; x++)
{
Console.Write(" Angka Ke-" + (x + 1) + " : ");
array[x] = int.Parse(Console.ReadLine());
}
Console.WriteLine();
Console.WriteLine(" Sebelum Diurutkan");
for (x = 0; x < angka; x++)
{
Console.Write(" " + array[x]);
}
Console.WriteLine();
for (int y = 0; y <= angka - 1; y++)
{
for (int z = 0; z <= angka - 2; z++)
{
if (array[z] > array[z + 1])
{
int temp = array[z + 1];
array[z + 1] = array[z];
array[z] = temp;
}
}
}
Console.WriteLine();
Console.WriteLine(" Ascending Sort");
for (x = 0; x < angka; x++)
{
Console.Write(" " + array[x]);
}
Console.WriteLine();
for (int y = 0; y <= angka - 1; y++)
{
for (int z = 0; z <= angka - 2; z++)
{
if (array[z] < array[z + 1])
{
int temp = array[z];
array[z] = array[z + 1];
array[z + 1] = temp;
}
}
}
Console.WriteLine();
Console.WriteLine(" Descending Sort");
for (int i = 0; i < angka; i++)
{
Console.Write(" " + array[i]);
}
Console.ReadLine();
}
}
}
{
class Program
{
static void Main(string[] args)
{
int angka, x;
Console.WriteLine();
Console.WriteLine(" ==========Metode Bubble Sort==============");
Console.WriteLine();
Console.Write(" Masukkan Banyak Angka : ");
angka = int.Parse(Console.ReadLine());
int[] array = new int[angka];
Console.WriteLine();
for (x = 0; x < angka; x++)
{
Console.Write(" Angka Ke-" + (x + 1) + " : ");
array[x] = int.Parse(Console.ReadLine());
}
Console.WriteLine();
Console.WriteLine(" Sebelum Diurutkan");
for (x = 0; x < angka; x++)
{
Console.Write(" " + array[x]);
}
Console.WriteLine();
for (int y = 0; y <= angka - 1; y++)
{
for (int z = 0; z <= angka - 2; z++)
{
if (array[z] > array[z + 1])
{
int temp = array[z + 1];
array[z + 1] = array[z];
array[z] = temp;
}
}
}
Console.WriteLine();
Console.WriteLine(" Ascending Sort");
for (x = 0; x < angka; x++)
{
Console.Write(" " + array[x]);
}
Console.WriteLine();
for (int y = 0; y <= angka - 1; y++)
{
for (int z = 0; z <= angka - 2; z++)
{
if (array[z] < array[z + 1])
{
int temp = array[z];
array[z] = array[z + 1];
array[z + 1] = temp;
}
}
}
Console.WriteLine();
Console.WriteLine(" Descending Sort");
for (int i = 0; i < angka; i++)
{
Console.Write(" " + array[i]);
}
Console.ReadLine();
}
}
}
Tidak ada komentar:
Posting Komentar