-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZoho32.java
66 lines (62 loc) · 1 KB
/
Zoho32.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.util.*;
import java.io.*;
class Zoho32
{
static void Dec_sort(int[] arr , int start , int end )
{
int i,j,flag=0;
do{
for(i=start; i < end-2 ; i=i+2 )
{
flag =0 ;
if(arr[i] < arr[i+2])
{
flag = 1;
int temp = arr[i];
arr[i] = arr[i+2];
arr[i+2] = temp ;
}
}
}while(flag == 1);
}
static void Asc_sort(int[] arr , int start , int end )
{
int i,j,flag=0;
do{
for(i=start; i < end-2 ; i=i+2 )
{
flag =0 ;
if(arr[i] > arr[i+2])
{
flag = 1;
int temp = arr[i];
arr[i] = arr[i+2];
arr[i+2] = temp ;
}
}
}while(flag == 1);
}
public static void main(String args[])
{
int n,i;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of elements : ");
n = sc.nextInt();
int[] a = new int[n];
System.out.println("Enter the elements : ");
for(i=0;i<n;i++)
{
a[i] = sc.nextInt();
}
for(i=0 ; i < n ; i++){
Asc_sort(a , 1 , n-1);
Dec_sort(a , 0 , n);
}
System.out.println();
System.out.println("RESULT :");
for(i=0;i<n;i++)
{
System.out.println(a[i]);
}
}
}