Count Sort Complete Code.
Counting
Sort Program
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace COUNT_SORT
{
class sorting
{
int n;
int[]
cs;
int[]
count;
int[]
s;
public
sorting() { }
public
sorting(int _n)
{
n = _n;
cs = new
int[n];
count = new
int[n];
s = new
int[n];
}
public void Countsort()
{
Console.WriteLine("Enter The value you want sort");
for
(int i = 0; i < n; i++)
{
cs[i] = Convert.ToInt32(Console.ReadLine());
}
for
(int i = 0; i < n; i++)
{
count[i] = 0;
}
for
(int i = 0; i < n - 1; i++)
{
for
(int j = i + 1; j < n; j++)
{
if
(cs[i] < cs[j])
{ count[j]++; }
else
{ count[i]++; }
}
}
for
(int i = 0; i < n; i++)
{
for
(int j = 0; j < n; j++)
{
Console.Write(s[j]);
}
Console.WriteLine();
s[count[i]] = cs[i];
}
for
(int j = 0; j < n; j++)
{ Console.Write(s[j]);
}
Console.WriteLine();
Console.ReadLine();
}
}
class Program
{
static void Main(string[]
args)
{
sorting
s = new sorting(10);
s.Countsort();
}
}
}
}
this is insertion sort
ReplyDelete