i have a array
{10,20,30,40,50 and so on}
and i want that this array be sorted in the form {20,10,40,30,60,50......}
how can i do this???
plz write the code i am unable to solve this.....
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 26, 2014, 11:07 PM EST
try....
int[] a = new int[10] { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
int count = (a.Length / 2) - 1;
int swapDataIndex = 0;
for (var arrayData = 0; arrayData <= count; arrayData++)
{
int dummyNo = a[swapDataIndex + 1];
a[swapDataIndex + 1] = a[swapDataIndex];
a[swapDataIndex] = dummyNo;
swapDataIndex += 2;
}
foreach (var datainArray in a)
{
Console.WriteLine(datainArray);
}
hope this will help you.
Lakshmanan Sethu SankaranarayanRank #124 · 17.7K reputationPosted Feb 26, 2014, 7:21 PM EST
Vipin TyagiRank #868 · 2.5K reputationPosted Feb 26, 2014, 9:51 PM EST
and we want to swap 1st element to 2nd ,3rd element with 4th 5th with 6 and so on.......
means if array is
1[0] index number
2[1]
3
4
5
6
7
8
9
10[9]
after swapping the element will be
2[0]index
1
4
3
6
5
8
7
10
9[9]index
VulpesRank #55 · 29.2K reputationPosted Feb 27, 2014, 1:08 AM EST
The output is:
20 10 40 30 60 50 80 70 100 90
Vipin TyagiRank #868 · 2.5K reputationPosted Feb 27, 2014, 1:59 AM EST