hello
i have this array ex :
int a [] = {2,1,4,5,3,7,6,9,8,10};
1- sorrting array by loop
i know this step
2- i didn't no this result :
1 2 3 4 5 10 9 8 7 6
how i will do it ??
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 attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Dec 7, 2014, 7:55 AM EST
VulpesRank #55 · 29.2K reputationPosted Dec 7, 2014, 6:47 AM EST
Dlovan Bakhtiar11 reputationPosted Dec 7, 2014, 7:10 AM EST
this is all of the function but i don't no why it didn't do it !!!
VulpesRank #55 · 29.2K reputationPosted Dec 7, 2014, 7:12 AM EST
Dlovan Bakhtiar11 reputationPosted Dec 7, 2014, 7:23 AM EST
so how reverse the second part of the array !!! ?? the loop you put it i don't where i put it !! but please it's better to do it just by 3 loops two loops for rhe sorrt and reverse one loops for print .
my regards
Dlovan Bakhtiar11 reputationPosted Dec 7, 2014, 8:08 AM EST
rigards Dlovan
VulpesRank #55 · 29.2K reputationPosted Dec 7, 2014, 8:31 AM EST
It should be possible to sort the first half of the (unsorted) array in ascending order and the second half in descending order within a single loop but that's not the same thing. For example if you had this to start with:
int[] a = {3, 1, 4, 10, 5, 7, 2, 8, 9, 6};
you'd end up with:
1, 3, 4, 5, 10, 9, 8, 7, 6, 2
rather than
1, 2, 3, 4, 5, 10, 9, 8, 7, 6
Perhaps that's what you remembered seeing before?
Dlovan Bakhtiar11 reputationPosted Dec 7, 2014, 9:00 AM EST
VulpesRank #55 · 29.2K reputationPosted Dec 7, 2014, 11:52 AM EST
int[] a = {3, 1, 4, 10, 5, 7, 2, 8, 9, 6};
int temp = 0;
The output should be:
1 3 4 5 10 9 8 7 6 2