using System;
public class Test
{
public static void Main()
{
int T = Convert.ToInt32(Console.ReadLine());
for(int i=0;i<T;i++)
{
string[] unSorted = Console.ReadLine().Split(' ');
int[] unSortedNumberArray = Array.ConvertAll(unSorted,int.Parse);
int n = unSortedNumberArray.Length;
BubbleSort(unSortedNumberArray,n);
}
}
public static void BubbleSort(int[] numbers,int n)
{
bool swapped = false;
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-i-1;j++)
{
int temp=-1;
if(numbers[j+1]<numbers[j])
{
temp = numbers[j];
numbers[j] = numbers[j+1];
numbers[j+1] = temp;
swapped = true;
}
}
if(swapped==false)
{
break;
}
}
foreach(int a in numbers )
{
Console.WriteLine(a);
}
}
}
public class Test
{
public static void Main()
{
int T = Convert.ToInt32(Console.ReadLine());
for(int i=0;i<T;i++)
{
string[] unSorted = Console.ReadLine().Split(' ');
int[] unSortedNumberArray = Array.ConvertAll(unSorted,int.Parse);
int n = unSortedNumberArray.Length;
BubbleSort(unSortedNumberArray,n);
}
}
public static void BubbleSort(int[] numbers,int n)
{
bool swapped = false;
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-i-1;j++)
{
int temp=-1;
if(numbers[j+1]<numbers[j])
{
temp = numbers[j];
numbers[j] = numbers[j+1];
numbers[j+1] = temp;
swapped = true;
}
}
if(swapped==false)
{
break;
}
}
foreach(int a in numbers )
{
Console.WriteLine(a);
}
}
}
Comments
Post a Comment