Given a array of random integers, sort the odd elements in descending order and even numbers in ascending order.
Example input: (1,4,5,2,3,6,7)
Output: (7,5,3,1,2,4,6)
Optimize for time complexity.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Which language is it, C or C++ (I see both tags)
In C++, you can use
std::sort()with appropriate ordering function. In C,qsort()works similarly: