Forums » .NET » .NET »

how to sort array in ascending and descending order without using in built funct in c#.net


Posted Date: 22 May 2008      Posted By:: anandraopatwari     Member Level: Silver    Member Rank: 0     Points: 1   Responses: 2





hello friends
i have to sort an array in Ascending and descending order with out using inbuilt functions like
array.sort() method

i have tried with this code
but it is not working

int[] a = {42, 54, 1, 14, 300};
int[] b = new int[31];
int temp;
string str = "";
for (int i = 0; i <= a.Length - 1; i++)
{
for (int j = 0; j <= a.Length - 1; j++)
{
if (j > a.Length)
{

if (a[i] > a[j])
{
temp = a[i];
a[i]= a[j];
a[j] = temp;

}
}
}
}

//Array.Sort(a)

for (int j = 0; j <= a.Length - 1; j++)
{
str = str + a[j]+ "" ;
}

Response.Write(str);
}

Thanks in advance




Responses

#234987    Author: Muhilan      Member Level: Gold      Member Rank: 0     Date: 22/May/2008   Rating: 2 out of 52 out of 5     Points: 2

for (int i = 0; i <= a.Length - 1; i++)
{
for (int j = 0; j <= a.Length - 1; j++)
{

if (a[i] > a[j])
{
temp = a[i];
a[i]= a[j];
a[j] = temp;


}
}
}

// remove third if condition and check out


 
#235497    Author: Sachin Kumar      Member Level: Gold      Member Rank: 840     Date: 23/May/2008   Rating: 2 out of 52 out of 5     Points: 2

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


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Return to Discussion Forum
Start new thread

Subscribe to Subscribers
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John

Online Members

saa saa
More...
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India