-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathccsort.java
More file actions
103 lines (98 loc) · 2.65 KB
/
ccsort.java
File metadata and controls
103 lines (98 loc) · 2.65 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import java.io.*;
class ccsort
{
static int c1,c2,r1,r2,i,j,c=0,m,n,k;
public static void main(String args[])throws IOException
{
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("ENTER SAMEDIMENSIONS OF ARRAY [M][M]");
m=Integer.parseInt(buf.readLine());
n=Integer.parseInt(buf.readLine());
int a[][]=new int[m][n];
if(m!=n)
System.out.println("ENTER AN ARRAY WITH SAME DIMENSION");
else
{
System.out.println("ENTER ELEMENTS OF ARRAY");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=Integer.parseInt(buf.readLine());
}
}
System.out.println("YOUR ARRAY IS .........");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
int b[]=new int[m*n];
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
b[c]=a[i][j];
c++;
}
}
c=0;
for(i=0;i<(m*n);i++)
{
for(j=0;j<(m*n)-i-1;j++)
{
if(b[j]>b[j+1])
{
int t=b[j];
b[j]=b[j+1];
b[j+1]=t;
}
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
b[c++]=a[i][j];
}
}
c=0;
for(j=0;j<=m/2;j++)
{
for(i=j;i<n;i++)
{
a[j][i]=b[c];
c++;
}
for(i=j+1;i<n;i++)
{
a[i][n-1]=b[c];
c++;
}
for(i=n-2;i>=j;i--)
{
a[n-1][i]=b[c];
c++;
}
for(i=n-2;i>j;i--)
{
a[i][j]=b[c];
c++;
}
n--;
}
System.out.println("<<<<<<<<CIRCULAR SORTED ARRAY IS>>>>>>>>> .........");
for(i=0;i<m;i++)
{
for(j=m-1;j>=0;j--)
{
System.out.print("["+a[j][i]+"]\t");
}
System.out.println();
}
}
}
}