bubleshort-manji
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace buble_sort
{
class Program
{
static void Main(string[] args)
{
int n;
Console.Write("MASUKAN JUMLAH INDEKS : ");
n = int.Parse(Console.ReadLine());
int[] bil = new int[n];
for (int i = 0; i < bil.Length; i++)
{
Console.Write("index ke {0} : ", i + 1);
bil[i] = int.Parse(Console.ReadLine());
}
Console.WriteLine("1. Ascending.");
Console.WriteLine("2. Descending.");
Console.WriteLine();
Console.Write("input pilihan :");
int z = int.Parse(Console.ReadLine());
if (z==1)
{
for (int i = 0; i < bil.Length; i++)
{
for (int a = i + 1; a < bil.Length; a++)
{
if (bil[a] < bil[i])
{
int temp = bil[i];
bil[i] = bil[a];
bil[a] = temp;
}
}
}
Console.WriteLine();
Console.Write("HASIL ASCCENDING : ");
for (int i = 0; i < bil.Length; i++)
{
Console.Write(bil[i] + " ");
}
}
if (z==2)
{
for (int i = 0; i < bil.Length; i++)
{
for (int a = i + 1; a < bil.Length; a++)
{
if (bil[a] > bil[i])
{
int t = bil[i];
bil[i] = bil[a];
bil[a] = t;
}
}
}
Console.WriteLine();
Console.Write("HASIL Descending : ");
for (int i = 0; i < bil.Length; i++)
{
Console.Write(bil[i] + " ");
}
}
Console.ReadLine();
}
}
}
Komentar
Posting Komentar