Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Input- 1 2 3 4 5 6
Output-2 1 4 3 6 5
The sorting should be similar like in the given following sequence. The numbers can be random.

What I have tried:

I tried to change the position of i. If i is even. I increase it by one. If I is odd. I decrease it by one.
Posted
Updated 25-Aug-18 15:41pm
Comments
Richard MacCutchan 25-Aug-18 9:47am    
What is your question?
OriginalGriff 25-Aug-18 10:01am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. So we have no idea why your "sort algorithm" should change sorted input into a higher state of entropy ... let alone what problems you are having doing it.

Use the "Improve question" widget to edit your question and provide better information.
Dave Kreskowiak 25-Aug-18 11:27am    
You single example doesn't have anything to do with swapping odd and even numbers. It's just swapping the 1st two characters with teach other, then the next two, and the next two.

There's no sorting rules here and you haven't provided any either.

Your question isn't answerable. If you can't CLEARLY define the problem and the rules to solve it to yourself, how are you going to describe it to us?

Even worse, how are you going to describe the algorithm to the computer, which is FAR more picky about how you do it?

1 solution

Quote:
Input- 1 2 3 4 5 6
Output-2 1 4 3 6 5
The sorting should be similar like in the given following sequence. The numbers can be random.

Your example is bad because the numbers are consecutive and already sorted, All it show is a swap of pairs on output.
Quote:
I tried to change the position of i. If i is even. I increase it by one. If I is odd. I decrease it by one.

Do not try to change values because it will fail on 2, 3, 4, 5, 6, 7 and on 2, 4, 6, 8.
Just do a normal sort, then swap pairs.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900