Bubble sort dry run. with all steps how bubble sort work. you can count exchange and comparisons also by adding counter in this code. basic and simple code of the bubble sort in c#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace sorting_algo_s
{
class salgos
{
int[] arr = new int[10];
public void getdata()
{
Console.WriteLine("inter value of array");
//arr = new int[10];
for (int i = 0; i < 10; i++)
{
arr[i] = Convert.ToInt32(Console.ReadLine());
}
}
public void bubblesort()
{
for (int i = 0 ; i < 10; i++)
{
Console.WriteLine();
for (int j =0; j < 10; j++)
{
if (arr[i] < arr[j])
{
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
Console.Write(arr[j]);
}
}
}
public void show()
{
Console.WriteLine("\nsorted");
//arr = new int[10];
for (int i = 0; i < 10; i++)
{
// Console.WriteLine(arr[i]);
}
}
}
class Program
{
static void Main(string[] args)
{
salgos a = new salgos();
a.getdata();
a.bubblesort();
Console.WriteLine("\nhttp://csharpcode13.blogspot.com/");
a.show();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace sorting_algo_s
{
class salgos
{
int[] arr = new int[10];
public void getdata()
{
Console.WriteLine("inter value of array");
//arr = new int[10];
for (int i = 0; i < 10; i++)
{
arr[i] = Convert.ToInt32(Console.ReadLine());
}
}
public void bubblesort()
{
for (int i = 0 ; i < 10; i++)
{
Console.WriteLine();
for (int j =0; j < 10; j++)
{
if (arr[i] < arr[j])
{
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
Console.Write(arr[j]);
}
}
}
public void show()
{
Console.WriteLine("\nsorted");
//arr = new int[10];
for (int i = 0; i < 10; i++)
{
// Console.WriteLine(arr[i]);
}
}
}
class Program
{
static void Main(string[] args)
{
salgos a = new salgos();
a.getdata();
a.bubblesort();
Console.WriteLine("\nhttp://csharpcode13.blogspot.com/");
a.show();
}
}
}
where is dry run sir
ReplyDelete