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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Dec 7, 2014, 4:52 PM
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
Dlovan BakhtiarPosted Dec 7, 2014, 2:00 PM
VulpesPosted Dec 7, 2014, 1:31 PM
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 BakhtiarPosted Dec 7, 2014, 1:08 PM
rigards Dlovan
VulpesPosted Dec 7, 2014, 12:55 PM
Dlovan BakhtiarPosted Dec 7, 2014, 12:23 PM
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
VulpesPosted Dec 7, 2014, 12:12 PM
Dlovan BakhtiarPosted Dec 7, 2014, 12:10 PM
this is all of the function but i don't no why it didn't do it !!!
VulpesPosted Dec 7, 2014, 11:47 AM