### Ascending order HELP. Hello guys, I really want your help cause im confused. So what i need to do is to write a program that randomise array and after that the first numbers need to be odds and on ascending order, after them the numbers need to be even and again on ascending order. Here is an example of an input "7 2 5 1 8 4" and the expected output need to be "1 5 7 2 4 8" , Im getting "1 5 7 8 4 2".
Here is my code.
 ``123456789101112131415161718192021222324252627282930`` ``````#include using namespace std; int main(){ int n; for(int i=0; i<6; i++) cin>>n[i]; for (int i = 0; i < 6; i++){ cout << n[i] << " "; } cout<n[j+1]){ int s=n[j+1]; n[j+1]=n[j]; n[j]=s; } if(n[j]%2==0){ int e=n[j+1]; n[j+1]=n[j]; n[j]=e; } } } for(int k=0;k<6;k++){ cout<
Last edited on If you can use them, the algorithms std::sort() and std::stable_partition() will do what you want. If you cannot, then take a look at the reference implementations of each for hints about how to make it work.
Topic archived. No new replies allowed.