anonymous
  • anonymous
how can i rearrange an array so all the even numbers will have indices less than those for the odd numbers. This is in C. I have code for the rest of the program
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
does order matters?
anonymous
  • anonymous
no order does not matter
anonymous
  • anonymous
void rearrange(int a[]) {int i, b[SIZE]; for(i=0;i

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
thats what i have so far
anonymous
  • anonymous
you can create new array and check old array if it's even and put those numbers there :D and later put odd numbers
anonymous
  • anonymous
I am not sure if i know how to do that but i can try. if(a[i]%2) {b[i] = a[i];} //store odd values into new array else{} //I am not sure what to do with it if its even then. make another array?
anonymous
  • anonymous
no you need to index from 0, not to same position
anonymous
  • anonymous
and then increment when you add number http://pastebin.com/F8HT8rmT
anonymous
  • anonymous
oh!!! okay that makes sense now. thanks for the help thomas, i appreciate it
anonymous
  • anonymous
i think it's bad solution but it works :D
anonymous
  • anonymous
ha I am sure there are other ways to do it but hey it works for me!
rsmith6559
  • rsmith6559
You could sort the numbers by their modulus value: qsort( number % 2 ); Something like that.
anonymous
  • anonymous
Actually this problem is very easy. Declare another integer array with same length, and then copy even numbers first, then append remaining numbers (thee odd ones) in last of the second array. The code snippet to do this is shown below: int[] arrange(int a[], size) { int *b = new int[size]; int index = 0; // variable to track position in second array // copy even numbers first for (int i = 0; i < size; ++i) { if (a[i]%2 == 0) { b[index] = a[i]; ++b; } } // copy all odd numbers for (int i = 0; i < size; ++i) { if (a[i]%2 != 0) { b[index] = a[i]; ++b; } } // now return new array return b; } Hope this will help you. Happy programming.

Looking for something else?

Not the answer you are looking for? Search for more explanations.