The below code in a console application show you how you can sort any collection of intergers by writing your own sort method in c#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ajuniv
{
class Program
{
static void Main(string[] args)
{
List<int> li = new List<int>();
li.Add(4);
li.Add(1);
li.Add(3);
li.Add(2);
foreach (var item in li)
{
Console.WriteLine(item);
}
MySortFunction(li);
Console.WriteLine("After sorting");
foreach (var item in li)
{
Console.WriteLine(item);
}
}
public static void MySortFunction(List<int> li)
{
int temp;
for (int i = 0; i < li.Count; i++)
{
for (int j = 0; j < li.Count; j++)
{
if (li[i] > li[j])
{
//Swap
temp = li[i];
li[i] = li[j];
li[j] = temp;
}
}
Console.WriteLine("..................................");
foreach (var item in li)
{
Console.WriteLine(item);
}
Console.WriteLine("..................................");
}
}
}
}
Please post if you have any questions in the below comment section so that we will help you out with the solution or other viewers of this post will may also help you.
Popular Posts
-
Here is the code: // => Brute Force Solution: O(m* n) static long arrayManipulation(int n, int[][] queries) { ...
-
Whatever it is one fine day everyone on this planet who are born have to die for sure. When you are close ones are with you, you wont know ...
-
HTML: <div class="outer-container"> <div class="inner-container"> <div class="t...
No comments:
Post a Comment