Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class OddEvenSort {
- static void oddEvenSort(int a[], int n)
- {
- for(int i=0; i<n; i++){
- for(int j=0; j<i; j++){
- if(a[i] % 2 !=0&&a[j] %2 == 0){
- int tmp = a[i];
- a[i] = a[j];
- a[j] = tmp;
- }
- if(a[i] > a[j] && a[i] % 2 == 0 && a[j] % 2 == 0){
- int tmp = a[i];
- a[i] = a[j];
- a[j] = tmp;
- }
- if(a[i] < a[j] && a[i] % 2 != 0 && a[j] % 2 != 0){
- int tmp = a[i];
- a[i] = a[j];
- a[j] = tmp;
- }
- }
- }
- }
- public static void main(String[] args) throws IOException{
- int i;
- BufferedReader stdin = new BufferedReader( new InputStreamReader(System.in));
- String s = stdin.readLine();
- int n = Integer.parseInt(s);
- s = stdin.readLine();
- String [] pom = s.split(" ");
- int [] a = new int[n];
- for(i=0;i<n;i++)
- a[i]=Integer.parseInt(pom[i]);
- oddEvenSort(a,n);
- for(i=0;i<n-1;i++)
- System.out.print(a[i]+" ");
- System.out.print(a[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement