.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

sorting

Posted By: Rama Krishna     Posted Date: September 21, 2010    Points:2   Category :C#
array consist of elements 8,6,4,9,3,7,2,5,1,i want to sort array without using builtin functions?anyone helps?

Responses
Author: Asha.MP          Accepted Answer   
Posted Date: September 21, 2010     Points: 10   

Hi..
please check this

static void Main(string[] args)
{
int[] Num = {8,6,4,9,3,7,2,5,1};

int small = Num[0];
int pos = 0;
int temp = 0;

for (int i = 0; i <= Num.Length - 1; i++)
{
small = Num[i];
for (int j = i + 1; j <= Num.Length - 1; j++)
{
if (small > Num[j])
{
small = Num[j];
pos = j;
}
}
temp = Num[i];
Num[i] = small;
Num[pos] = temp;
}

Console.WriteLine("sorted array");
for (int i = 0; i <= Num.Length - 1; i++)
{
Console.WriteLine(Num[i]);
}
Console.ReadLine();
}

Thanks and Regards,
Asha.mp


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend