using System;
public class Test
{
public static void Main()
{
string [] UnsortedNumbers = Console.ReadLine().Split(' ');
int[] intUnsorted = Array.ConvertAll(UnsortedNumbers,int.Parse);
SelectionSort(intUnsorted);
printarr(intUnsorted);
}
public static void SelectionSort(int[] a)
{
int n= a.Length;
for(int i=0;i<n-1;i++)
{
int min = i;
for(int j=i+1;j<n;j++)
{
if(a[j]<a[min])
{
min = j;
}
}
Console.WriteLine("min "+min+" i-"+i+"a[min] and a[i] are respectively "+a[min]+" "+a[i]);
int temp=a[min];
a[min]= a[i];
a[i]=temp;
Console.WriteLine("a[min] and a[i] are respectively "+a[min]+" "+a[i]);
}
}
public static void printarr(int[] array)
{
foreach(int a in array)
{
Console.WriteLine(a);
}
}
}
public class Test
{
public static void Main()
{
string [] UnsortedNumbers = Console.ReadLine().Split(' ');
int[] intUnsorted = Array.ConvertAll(UnsortedNumbers,int.Parse);
SelectionSort(intUnsorted);
printarr(intUnsorted);
}
public static void SelectionSort(int[] a)
{
int n= a.Length;
for(int i=0;i<n-1;i++)
{
int min = i;
for(int j=i+1;j<n;j++)
{
if(a[j]<a[min])
{
min = j;
}
}
Console.WriteLine("min "+min+" i-"+i+"a[min] and a[i] are respectively "+a[min]+" "+a[i]);
int temp=a[min];
a[min]= a[i];
a[i]=temp;
Console.WriteLine("a[min] and a[i] are respectively "+a[min]+" "+a[i]);
}
}
public static void printarr(int[] array)
{
foreach(int a in array)
{
Console.WriteLine(a);
}
}
}
Comments
Post a Comment